gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
74.63k stars 7.45k forks source link

Fix base template lookup order for sections #2995

Closed dmitriid closed 7 years ago

dmitriid commented 7 years ago

What's happening

(also see img below)

This happens on both Hugo 0.18.1 and Hugo 0.19-DEV. Didn't happen on Hugo 0.18-DEV

I have a theme, with default layouts defined as follows: ./themes/freja/layouts/_default/{baseof,list,single}.html

For the gen section of the website I've overriden all of them: ./themes/freja/layouts/gen/{baseof,list,single}.html

And now the section's baseof template isn't used.

Screenshot of the file tree:

./themes/freja/layouts/_default/baseof.html is a regular html file:

<!DOCTYPE html>
<html lang="{{.Site.LanguageCode}}">
...
<body>
<main>
  {{ block "main" . }}
  {{ end }}
</main>
</body>
</html>

whereas ./themes/freja/layouts/gen/baseof.html is just a shell:

{{ block "main" . }}

{{ end }}

The rest of the templates are quite similar.

The result for /gen should look like this: https://dmitriid.com/gen/social/ Now, however, the output is surrounded by HTML from the theme's default baseof.html

dmitriid commented 7 years ago

Is there any idea why this might be happening?

bep commented 7 years ago

Where in the documentation did you find the /layouts/gen (the name of your section, I assume) syntax?

dmitriid commented 7 years ago

In https://gohugo.io/templates/content/

/gen/ is a section of the website (see /content/gen). In 0.18-DEV hugo was correctly picking the layout for gen from /themes/THEME/layouts/SECTION/ according to https://gohugo.io/templates/content/

And then it stopped for some reason.

I can give you access to the repository in the screenshot, if you want to try running this.

bep commented 7 years ago

OK, I now see that the documentation is inconsistent about this, see

https://gohugo.io/templates/list/

So your syntax is correct for single templates, but not list, which does not make much sense. We will have to fix that.

But in the meantime, I would recommend sticking with this documentation re. the base templates:

https://gohugo.io/templates/blocks/

Moving your section template to

/layouts/section/gen-baseof.html

Should do the trick.

dmitriid commented 7 years ago

Thank you for your reply!

I'm still a bit confused with all the sections :)

Because the following happened (MacOS, hugo v0.18.1):

New structure:

gen-baseof.html

{{ block "main" . }}

{{ end }}

single.html

{{ define "main" }}
  {{ .Content }}
{{ end }}

The generated file for a single entry (accessible in browser from http://localhost:1313/gen/social/) still has the outer shell from _default/baseof.html and _default/single.html

The generated file for "section list" (accessible in browser from http://localhost:1313/gen/) gets its outer shell from _default/baseof.html and everything else from section/gen.html

bep commented 7 years ago

I added some tests, and I cannot reproduce what you say in your last post.

Take this further on the discussion forum (start a new thread, and please post a reference to a full source repo that demonstrates your issue).

bep commented 7 years ago

OK, my test was wrong ... There is a issue here, but I will have to look closer into it.

dmitriid commented 7 years ago

I will post a link to the repo where this can be reproduced later today. Thank you for looking into this!

bep commented 7 years ago

Note:

If you add:

mysection/
   baseof.html
   list.html
   single.html

This should now work as expected.

Also note that with:

_default/
   single.html
   baseof.html
mysection/
   baseof.html
   list.html

The single pages in /mysection will get the base template from _default.

dmitriid commented 7 years ago

Thanks! I'll try this out ASAP

dmitriid commented 7 years ago

Ok, tried it out. The error is still there for themes.

Full version (based on this project):

$ ~/.go/bin/hugo version
Hugo Static Site Generator v0.20-DEV darwin/amd64 BuildDate: 2017-03-03T11:49:53+01:00

$ ~/.go/bin/hugo server --buildDrafts --theme=freja -v

The following layout works:

The following doesn't work:

I'll go with layouts in the root directory for now, but it would be nice to have the same behaviour for themes, too

dmitriid commented 7 years ago

Awesome! Thanks!

github-actions[bot] commented 2 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.