[FIXED] Calling partial without specifying .html suffix

Hi,

I started seeing the below error after a recent build from master branch. (This did not show up in the master build about a week or 10 days ago).

ERROR 2017/04/04 00:00:58 Error while rendering “page”: template: /home/kmodi/hugo/kaushalmodi.gitlab.io/themes/refined/layouts/_default/single.html:4:7: executing “/home/kmodi/hugo/kaushalmodi.gitlab.io/themes/refined/layouts/_default/single.html” at <partial “head” .>: error calling partial: Partial “head” not found

What I am doing:

  • I have a baseof.html that calls a partial named head: baseof.html#L4
  • In baseof.html, I have a block named main: baseof.html#L32. There’s also a block called after_main.
  • In single.htmlsingle.html, and other layout html files too, I define the main and after-main blocks.
  • I do have the partial called head defined: head.html.

But the above error says that the Partial “head” was not found.


You can recreate this error by building my site, which contains my theme refined as a git submodule.

@kaushalmodi Can you do me a favor and append .html to all your partial calls and see if that fixes the issue?

@kaushalmodi i suspect it is the suffix, and I will fix that (I thought I had that covered):

Note that from Hugo 0.20 the suffix will start to make some difference, but we will still append and look for partials with *.html to avoid breakage.

Thanks. That fixes this error. So essentially, it is now recommended to use the file extension in partial calls?
Also, I was glad to see the use of “.html” in calls consistently everywhere in the examples on Partial templates | Hugo

The old docs page ( Partial templates | Hugo ) still has:

To reference a partial template stored in a subfolder, e.g. /layouts/partials/post/tag/list.html, call it this way:

{{ partial "post/tag/list" . }}

Note that the subdirectories you create under /layouts/partials can be named whatever you like.


Thanks! I do not mind making this change.


Update: Done!

I will fix it so we don’t break existing templates, but yes, when you start getting more content output formats, it will soon start to make sense to include the suffix – that has always worked, btw., so it is backwards compatible.

As far as i can tell it is still not working in 0.20 as it was working before, when using other suffixes like .css for partials.

My previously working templates (in 0.18, …) are not running anymore in 0.20.
For examples, i had a partial/styles.css file included with :

 <style>
  {{ replaceRE " +" " " (replaceRE "\n" "" (partial "styles.css" .)) | safeCSS }}
 </style>

which now leads to the error :

ERROR 2017/04/11 11:52:41 Error while rendering “404”: template: /hugo-blog/themes/mytheme/layouts/404.html:18:48: executing “/hugo-blog/themes/mytheme/layouts/404.html” at <partial “styles.css”…>: error calling partial: Partial “styles.css” not found

If i rename the styles.css file into styles.html (filesystem with same location + partial included with “styles.html”), then everything works fine again !

I can confirm SR-G’s issue. I too was doing a

 <style>{{ partial "style.css" . | safeCSS }}</style>

in my header.html, and get

Error while rendering “page”: template: theme/_default/single.html:1:3: executing “theme/_default/single.html” at <partial "header.html…>: error calling partial: template: theme/partials/header.html:21:3: executing “theme/partials/header.html” at <partial “style.css” …>: error calling partial: Partial “style.css” not found

Changing everything to “style.css.html” did not work (!!)

Changing everything to ‘style.html’ had things working again.

The above is as designed, but I didn’t expect it to break existing sites. It is described here, and we will probably lift this restriction for Hugo 0.21:

I can confirm that it is working with for example “styles.css” in my old templates now with hugo 0.20.2. Thanks.

1 Like