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

Baseof.html in a theme is prioritized over non-theme peer equivalent #3505

Closed
ntharani opened this issue May 22, 2017 · 10 comments · Fixed by #4377
Closed

Baseof.html in a theme is prioritized over non-theme peer equivalent #3505

ntharani opened this issue May 22, 2017 · 10 comments · Fixed by #4377
Milestone

Comments

@ntharani
Copy link

ntharani commented May 22, 2017

UPDATE: All cases work except #5 in V 0.21. (Case #5 works in V 0.19)

  • Using latest MacOSX 10.12.4 & Hugo 0.20.7 (Tested known good on 0.19).
  • I created a github repo to show this behaviour. It works on 0.19.
  • I used brew switch hugo 0.19 to flip back and forth to verify issue.
  • https://github.com/ntharani/hugoblock (To verify issue)
  • I did my best to follow the guidelines and pretty sure this a bug, but if I haven't understood a quirk of how the new output formats or my syntax is wrong please let me know. Thanks.

Setup

  • Main layout baseof.html > styles-primary.css = blackbackground
  • Theme layout baseof.html > styles-theme.css = greenbackground

To test: Rename files to simulate unavailability.

  • Eg: "index.html" -> "Xindex.html"
  • Eg: "baseof.html" -> "Xbaseof.html"

Expected Behaviour

Observed Behaviour

I tried all the 0.20 branches - same behaviour as 0.20.7. This same behaviour happens with sections, like blog, but index was easier to verify.

├── layouts
│   ├── Xindex.html
│   └── _default
│   └── baseof.html
├── static
│   └── css
│   └── styles-primary.css
└── themes
└── hyper
│   └── default.md
├── layouts
│   ├── _default
│   │   ├── Xbaseof.html
│   │   ├── list.html
│   │   └── single.html
│   ├── index.html
├── static
│   ├── css
│   │   └── styles-theme.css
└── theme.toml

@ntharani
Copy link
Author

ntharani commented May 23, 2017

Update: All cases work except #5 on v.021 (Downloaded to test). I'm not sure if case #5 is by design or a bug so I submit it here for comment. But I believe it should defer to any non-theme equivalent peer that exists. (Eg; if baseof.html is specified in both places, the non-theme variant should take preference)

~/Downloads/hh3/hugo version
Hugo Static Site Generator v0.21 darwin/amd64 BuildDate: 2017-05-22T06:11:48-07:00

@ntharani ntharani changed the title Bug in Hugo 0.20.x branch with blocks and templates (works on 0.19) Hugo 0.21 Bug: Baseof.html in a theme is prioritized over non-theme peer equivalent. (Case #5). May 23, 2017
@ntharani ntharani changed the title Hugo 0.21 Bug: Baseof.html in a theme is prioritized over non-theme peer equivalent. (Case #5). 0.21 Bug: Baseof.html in a theme is prioritized over non-theme peer equivalent. (Case #5). May 23, 2017
@bep bep changed the title 0.21 Bug: Baseof.html in a theme is prioritized over non-theme peer equivalent. (Case #5). Baseof.html in a theme is prioritized over non-theme peer equivalent. (Case #5). May 23, 2017
@bep bep changed the title Baseof.html in a theme is prioritized over non-theme peer equivalent. (Case #5). Baseof.html in a theme is prioritized over non-theme peer equivalent May 23, 2017
@luaz
Copy link

luaz commented Jul 30, 2017

I assume this bug still persist in v25.1, or I am not sure of what is the default behavior.

I overwrite /layouts/_default/baseof.html expecting every page to have the same base, but it seems Hugo still prioritize the base from the theme /themes/xxx/layouts/_default/baseof.html.

Hugo will only prioritze /layouts/_default/baseof.html if I overwrite (the theme also contains _default/list.html and _default/single.html) the following as well

  • /layouts/_default/list.html
  • /layouts/_default/single.html

@ntharani
Copy link
Author

ntharani commented Aug 2, 2017

Hey.. yeah looks that way. I actually took a look at their go templates, but I'm not strong enough in go to debug it. It worked in V0.18 as I recall, but since then considerable work has gone in to support multiple output formats. I ended up just refactoring my code so that I work completely out of the theme directory. This repo was designed to show those cases.

@jonnermut
Copy link

I think I came across this in v0.26 after following the quickstart:

  1. Follow all the instructions in the quick start (except making a blog post)
  2. I wanted to change the font (it should be parametized...). Worked out where it was set, then read the doco on how to customise a theme. Copied /themes/anake/layouts/_default/baseof.html to /layouts/_default/baseof.html and modified
  3. hugo still uses the them baseof.html

Much frustration for a new user working out whats going on. I ended up hacking the theme files.

@IAmAdamTaylor
Copy link

+1 - I'm having the same issue.

The build process will only use layouts/_default/baseof.html if I overwrite other templates defined within the themes/themename/layouts/_default/ folder.

It seems to be related to which template is currently showing. I can setup the site and theme so that my baseof.html overrides are used on some pages but not others.

To reproduce

Follow the quick start instructions and then perform these steps:

  1. Copy the files from themes/ananke/exampleSite/ to the main Hugo directory so there is some content to work with.
  2. Copy themes/ananke/layouts/_default/baseof.html to layouts/_default/baseof.html
  3. Change layouts/_default/baseof.html in some way. I opted for adding a <h1>Testing</h1> after the opening <body> tag for easy debugging between pages.
  4. Start running the Hugo server and navigate to the home page. You will not see any changes as Hugo still favours the theme file over the main file.
  5. Copy the themes/ananke/layouts/_default/list.html to layouts/_default/list.html
  6. Observe that the <h1> tag is present on the home page.
  7. Navigate to a single post page and observe that the <h1> tag is not present.
  8. Copy themes/ananke/layouts/_default/single.html to layouts/_default/single.html
  9. Observe that the <h1> tag is now present on the single post page due to the override of the single.html template.

@niconoe
Copy link

niconoe commented Oct 17, 2017

+1, I also encountered this issue with Hugo 0.30 and found it quite confusing for a newbie like me.

I guess the main question is: is the behavior considered correct?

  • If so, I suggest being a bit more explicit (warning message?) in the documentation, especially the "Base templates" and "Lookup order" sections.
  • If not, it would be great to solve the bug. I'd prefer this second option, since the current situation is not really clean in term of theme overriding: to override baseof.html, we also have to copy (in layouts/_default) several files we in fact don't plan to change at all.

@areohbe
Copy link

areohbe commented Nov 27, 2017

I am also encountering this issue as well. Creating baseof.html within layouts/_defaults does not override the theme layout. Any update?

@shosanna
Copy link

shosanna commented Feb 3, 2018

having the same issue, any update please? I do not know what to do except hacking the theme file...

moorereason added a commit to moorereason/hugo that referenced this issue Feb 4, 2018
The tplimpl package was misusing the TemplateLookupDescriptor.WorkingDir
field from the output package. By incorrectly setting it to the theme
directory instead of the site root, the user is unable to override theme
templates in some situations.

Fixes gohugoio#3505
@IAmAdamTaylor
Copy link

@shosanna I haven’t seen any updates yet, but a workaround is to copy the whole layouts folder from the theme to your site and then override the baseof.html.

Because you have all of the templates in the site it’ll use your baseof.html by default.

moorereason added a commit to moorereason/hugo that referenced this issue Feb 5, 2018
Add an additional test to "Variant 4, theme, use site base" to also test
for the index.html base (from by testing of gohugoio#3505).  Also add a "name"
field to the test cases to make it easier to know which test is failing
versus just getting a slice index.
moorereason added a commit to moorereason/hugo that referenced this issue Feb 5, 2018
The tplimpl package was misusing the TemplateLookupDescriptor.WorkingDir
field from the output package. By incorrectly setting it to the theme
directory instead of the site root, the user is unable to override theme
templates in some situations.

Fixes gohugoio#3505
@bep bep added this to the v0.36 milestone Feb 5, 2018
@bep bep closed this as completed in #4377 Feb 5, 2018
bep pushed a commit that referenced this issue Feb 5, 2018
Add an additional test to "Variant 4, theme, use site base" to also test
for the index.html base (from by testing of #3505).  Also add a "name"
field to the test cases to make it easier to know which test is failing
versus just getting a slice index.
bep pushed a commit that referenced this issue Feb 5, 2018
The tplimpl package was misusing the TemplateLookupDescriptor.WorkingDir
field from the output package. By incorrectly setting it to the theme
directory instead of the site root, the user is unable to override theme
templates in some situations.

Fixes #3505
@github-actions
Copy link

github-actions bot commented Mar 8, 2022

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 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants