Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix base template lookup order for sections #2995

Closed
dmitriid opened this issue Jan 28, 2017 · 13 comments
Closed

Fix base template lookup order for sections #2995

dmitriid opened this issue Jan 28, 2017 · 13 comments
Assignees
Milestone

Comments

@dmitriid
Copy link
Contributor

dmitriid commented Jan 28, 2017

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
Copy link
Contributor Author

dmitriid commented Feb 6, 2017

Is there any idea why this might be happening?

@bep
Copy link
Member

bep commented Feb 6, 2017

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

@dmitriid
Copy link
Contributor Author

dmitriid commented Feb 6, 2017

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
Copy link
Member

bep commented Feb 6, 2017

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.

@bep bep changed the title Section's baseof template overriden by theme baseof Make section template selection consistent Feb 6, 2017
@dmitriid
Copy link
Contributor Author

dmitriid commented Feb 6, 2017

Thank you for your reply!

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

  • Section template goes into /layouts/section/gen-baseof.html
  • What was list template goes into /layouts/section/gen.html?
  • What was single template goes into ?

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 added a commit that referenced this issue Feb 6, 2017
@bep
Copy link
Member

bep commented Feb 6, 2017

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 bep changed the title Make section template selection consistent Fix base template lookup order for sections Feb 6, 2017
@bep bep added the Bug label Feb 6, 2017
@bep
Copy link
Member

bep commented Feb 6, 2017

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

bep added a commit that referenced this issue Feb 6, 2017
This reverts commit d11f37d.

Will have to look more closely into this.

See #2995
@dmitriid
Copy link
Contributor Author

dmitriid commented Feb 7, 2017

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

@bep bep added this to the v0.20 milestone Feb 28, 2017
@bep bep self-assigned this Mar 2, 2017
@bep bep closed this as completed in 5a94e4c Mar 2, 2017
@bep
Copy link
Member

bep commented Mar 2, 2017

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
Copy link
Contributor Author

dmitriid commented Mar 2, 2017

Thanks! I'll try this out ASAP

@dmitriid
Copy link
Contributor Author

dmitriid commented Mar 3, 2017

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

@bep bep reopened this Mar 3, 2017
dmitriid added a commit to dmitriid/dmitriid.com that referenced this issue Mar 9, 2017
@bep bep mentioned this issue Mar 20, 2017
26 tasks
bep added a commit to bep/hugo that referenced this issue Mar 27, 2017
Extract the logic to a testable function and add support for custom output types.

Fixes gohugoio#2995
@bep bep closed this as completed in baa29f6 Mar 27, 2017
@dmitriid
Copy link
Contributor Author

Awesome! Thanks!

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants