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 · 12 comments

Comments

Projects
None yet
2 participants
@dmitriid
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

This comment has been minimized.

Show comment
Hide comment
@dmitriid

dmitriid Feb 6, 2017

Contributor

Is there any idea why this might be happening?

Contributor

dmitriid commented Feb 6, 2017

Is there any idea why this might be happening?

@bep

This comment has been minimized.

Show comment
Hide comment
@bep

bep Feb 6, 2017

Member

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

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

This comment has been minimized.

Show comment
Hide comment
@dmitriid

dmitriid Feb 6, 2017

Contributor

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.

Contributor

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

This comment has been minimized.

Show comment
Hide comment
@bep

bep Feb 6, 2017

Member

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.

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 from Section's baseof template overriden by theme baseof to Make section template selection consistent Feb 6, 2017

@dmitriid

This comment has been minimized.

Show comment
Hide comment
@dmitriid

dmitriid Feb 6, 2017

Contributor

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

Contributor

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

This comment has been minimized.

Show comment
Hide comment
@bep

bep Feb 6, 2017

Member

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).

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 from Make section template selection consistent to Fix base template lookup order for sections Feb 6, 2017

@bep bep added the Bug label Feb 6, 2017

@bep

This comment has been minimized.

Show comment
Hide comment
@bep

bep Feb 6, 2017

Member

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

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

Revert "hugolib: Add some baseof test variants"
This reverts commit d11f37d.

Will have to look more closely into this.

See #2995
@dmitriid

This comment has been minimized.

Show comment
Hide comment
@dmitriid

dmitriid Feb 7, 2017

Contributor

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

Contributor

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 in 5a94e4c Mar 2, 2017

@bep

This comment has been minimized.

Show comment
Hide comment
@bep

bep Mar 2, 2017

Member

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.

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

This comment has been minimized.

Show comment
Hide comment
@dmitriid

dmitriid Mar 2, 2017

Contributor

Thanks! I'll try this out ASAP

Contributor

dmitriid commented Mar 2, 2017

Thanks! I'll try this out ASAP

@dmitriid

This comment has been minimized.

Show comment
Hide comment
@dmitriid

dmitriid Mar 3, 2017

Contributor

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

Contributor

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 referenced this issue Mar 20, 2017

Closed

Add custom output formats #2828

26 of 26 tasks complete

bep added a commit to bep/hugo that referenced this issue Mar 27, 2017

output: Rework the base template logic
Extract the logic to a testable function and add support for custom output types.

Fixes #2995

@bep bep closed this in baa29f6 Mar 27, 2017

@dmitriid

This comment has been minimized.

Show comment
Hide comment
@dmitriid

dmitriid Mar 27, 2017

Contributor

Awesome! Thanks!

Contributor

dmitriid commented Mar 27, 2017

Awesome! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment