Hugo: Baseof.html in a theme is prioritized over non-theme peer equivalent

Created on 23 May 2017  Β·  9Comments  Β·  Source: gohugoio/hugo

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

  • #1 Main > layouts > index.html & Main > layouts > baseof.html == White Text / Black Background
  • #2 Main > layouts > index.html & Theme > layouts > baseof.html == White Text / Green Background
  • #3 Theme > layouts > index.html & Theme > layouts > baseof.html == White Text / Green Background
  • #4 Theme > layouts > index.html & Main > layouts > baseof.html == White Text / Black Background
  • #5 Theme > layouts > index.html & Theme > layouts > baseof.html & Main > layouts > baseof.html == White Text / Black Background (if baseof.html exists in the primary folder it should take precedence over it's theme equivalent)

Observed Behaviour

  • #4 V0.20.7 Results in a Blank Page. This should be white text on a black background.
  • #4 V0.19 Works: white text on a black background.

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

Bug

Most helpful comment

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

All 9 comments

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

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

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.

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.

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

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

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

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

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

VoidingWarranties picture VoidingWarranties  Β·  3Comments

vielmetti picture vielmetti  Β·  3Comments

arikroc picture arikroc  Β·  3Comments

moorereason picture moorereason  Β·  3Comments

marekr picture marekr  Β·  3Comments