hugo new theme does not create a baseof.html

Created on 10 Jun 2017  ยท  19Comments  ยท  Source: gohugoio/hugo

As Block-Templates are the new default I think that the directory layout of a theme created by hugo new should reflect this and create a baseof.html in _default.

Keep

Most helpful comment

And we crossed streams. Oops.

All 19 comments

Hello @juh2,

Block-Templates are the new default I think

We make no assumptions about the user and the structure of his theme. Block templates are still optional, hence they don't have to be used by default.

But it would make sense to encourage theme creators to make use of baseof.html since it removes a lot of redundancy. Creating a baseof.html when executing hugo new theme xyz might also help to increase its adaption.

If you think baseof.html should be created by default then label this issue as a feature request.

What remains is the question whether the adoption of block templates outweighs the assumptions of the users and his intended theme structure.

Thanks for the clarification.

I see no obvious button to label this issue as feature request.

Could someone with more insight or rights do this?

TIA

I agree with @juh2 that most would really want a baseof.html if they knew about it. But we should then set up a basic structure with a content section etc.

Here's what is currently generated:

.
โ”œโ”€โ”€ LICENSE.md
โ”œโ”€โ”€ archetypes
โ”‚ย ย  โ””โ”€โ”€ default.md
โ”œโ”€โ”€ layouts
โ”‚ย ย  โ”œโ”€โ”€ 404.html
โ”‚ย ย  โ”œโ”€โ”€ _default
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ list.html
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ single.html
โ”‚ย ย  โ”œโ”€โ”€ index.html
โ”‚ย ย  โ””โ”€โ”€ partials
โ”‚ย ย      โ”œโ”€โ”€ footer.html
โ”‚ย ย      โ””โ”€โ”€ header.html
โ”œโ”€โ”€ static
โ”‚ย ย  โ”œโ”€โ”€ css
โ”‚ย ย  โ””โ”€โ”€ js
โ””โ”€โ”€ theme.toml

How about the addition of baseof.html, shortcodes, and img? Seems like content and data should stay independent of the theme scaffolding. Also, I'm not especially firm on img:

.
โ”œโ”€โ”€ LICENSE.md
โ”œโ”€โ”€ archetypes
โ”‚ย ย  โ””โ”€โ”€ default.md
โ”œโ”€โ”€ layouts
โ”‚ย ย  โ”œโ”€โ”€ 404.html
โ”‚ย ย  โ”œโ”€โ”€ _default
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ baseof.html
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ list.html
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ single.html
โ”‚ย ย  โ”œโ”€โ”€ index.html
โ”‚ย ย  โ”œโ”€โ”€ partials
โ”‚ย ย  โ”‚ โ”œโ”€โ”€ footer.html
โ”‚ย ย  โ”‚ โ””โ”€โ”€ header.html
โ”‚ย ย  โ””โ”€โ”€ shortcodes
โ”œโ”€โ”€ static
โ”‚ย ย  โ”œโ”€โ”€ css
โ”‚ย ย  โ”œโ”€โ”€ img
โ”‚ย ย  โ””โ”€โ”€ js
โ””โ”€โ”€ theme.toml

Let us keep this issue about ... besof.html and not add a lot of other issues on top.

You mentioned a content section as well, so I was running with it. Is this in the "beginner" or "easy" category,@bep? Maybe I can give it a shot :smile:

The general tenor of the comments seems to supports this proposal. I would to extend this thought by linking the files together as follows:

Hugo generates header.html and footer.html by default. So the baseof.html would look like this:

{{- partial "header.html" . -}}

{{- block "main" . }}{{- end }}

{{- partial "footer.html" . -}}

404.html, list.html, single.html and index.html would consist of

{{- define "main" }}{{- end }}

I would second the idea of including some partial calls as noted above by @digitalcraftsman. Simple enough to clue in new users and not so complicated that people end up deleting a bunch of scaffolding to get up and running...

@digitalcraftsman I think the header/footer is an antipattern that the baseof.html solves -- and we should fix that. In the example you give, neither the header nor the footer is well-formed HTML document that can easily be edited/formatted by an editor. The baseof.html should form a simple and well formed HTML document with closing tags.

@bep with my understanding of your comment you propose that baseof.html should contain the whole skeleton for a page, i.e. it "should form a simple and well formed HTML document with closing tags.".

Would a minimalistic baseof.html would look like this?

<html>
    <head>
        <title>Hugo</title>
        <!-- some other stuff -->
    </head>
    <body>
        <div id="content">
        {{- block "main" . }}{{- end }}
        </div>

        <footer>
            <!-- copyright etc. -->
        </footer>
    </body>
</html>

I see the inclusion of the header.html and footer.html in baseof.html as a composition of simple templates that form a larger and more complex one.

The partial pattern is still useful and should still be part of the scheleton, as long as the templates are well formed:

<html>
    {{- partial "header.html" . -}}
    <body>
        <div id="content">
        {{- block "main" . }}{{- end }}
        </div>
        {{- partial "footer.html" . -}}
    </body>
</html>

Or variants of the above. In the above, all templates are well formed (base + footer + partial).

Got it.

If I may get more granular, I would only suggest that there be a head.html and a header.html since head.html tends to get very big very quickly:

<html>
    <head>
    {{- partial "head.html" . -}}
    </head>
    <body>
        {{- partial "header.html" . -}}
        <div id="content">
        {{- block "main" . }}{{- end }}
        </div>
        {{- partial "footer.html" . -}}
    </body>
</html>

Anything more than this, though, and I'm probably just getting too opinionated :smile:

@rdwatters sure, but in your example head.html would not be well formed on its own.

This would be a good start:

<html>
    {{- partial "head.html" . -}}
    <body>
        {{- partial "header.html" . -}}
        <div id="content">
        {{- block "main" . }}{{- end }}
        </div>
        {{- partial "footer.html" . -}}
    </body>
</html>

How about...

<html>
    {{- partial "head.html" . -}}
    <body>
        {{- partial "header.html" . -}}
        <div id="content">
        {{- block "main" . }}{{- end }}
        </div>
        {{- partial "footer.html" . -}}
    </body>
</html>

And we crossed streams. Oops.

This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help.
If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open.
If this is a feature request, and you feel that it is still relevant and valuable, please tell us why.
This issue will automatically be closed in the near future if no further activity occurs. Thank you for all your contributions.

I got here from:

  1. #4808
  2. https://discourse.gohugo.io/t/what-are-the-pros-cons-of-using-a-baseof-template-or-the-standard-template/8048/4
  3. https://github.com/gohugoio/hugo/issues/3576#issuecomment-307637628

digitalcraftsman wrote:

But it would make sense to encourage theme creators to make use of baseof.html since it removes a lot of redundancy. Creating a baseof.html when executing hugo new theme xyz might also help to increase its adaption.

Sounds like a great idea!

Both bep and rdwatters wrote:

<html>
    {{- partial "head.html" . -}}
    <body>
        {{- partial "header.html" . -}}
        <div id="content">
        {{- block "main" . }}{{- end }}
        </div>
        {{- partial "footer.html" . -}}
    </body>
</html>

Hohoho! Great minds think alike!

Since everyone has come to a consensus, I think it would be interesting to implement it in hugo new theme and maybe even in hugo new site (in a new interactive mode) with more instruction and guidance to the person starting a new website or a new theme. With new theme especially, perhaps some guidance can ben written and some recommended licenses be offered...

Was this page helpful?
0 / 5 - 0 ratings