hugo-PaperMod: Missing template definitions breaks production builds in Hugo v0.146.0+

What you’d like to propose?

Hi!

In the latest version of PaperMod, the following templates are referenced inside _partials/head.html:

{{ template "partials/templates/opengraph.html" . }}
{{ template "partials/templates/twitter_cards.html" . }}
{{ template "partials/templates/schema_json.html" . }}

However, these templates are not defined in the theme (using {{ define … }}), which causes the Hugo build to fail in production mode:

Error: html/template:_partials/head.html:155:13: no such template "partials/templates/twitter_cards.html"

This is especially confusing because it only triggers in production (i.e., hugo.IsProduction == true), so users upgrading from an older version may not notice the issue until CI breaks.

Suggested Fix:

  • Provide empty stub templates for these in layouts/partials/templates/, e.g.:
{{ define "partials/templates/twitter_cards.html" }}{{ end }}

That way, users can override them if needed, but the build won’t fail by default.

Thanks for the great theme!

Code of Conduct

  • I agree to follow this project’s Code of Conduct

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 17
  • Comments: 22 (16 by maintainers)

Commits related to this issue

Most upvoted comments

These are the required theme changes to be compatible with v0.146.0 and later.

diff --git a/layouts/partials/head.html b/layouts/partials/head.html
index 3e55c67..ae6450a 100644
--- a/layouts/partials/head.html
+++ b/layouts/partials/head.html
@@ -150,8 +150,8 @@
 
 {{- /* Misc */}}
 {{- if hugo.IsProduction | or (eq site.Params.env "production") }}
-{{- template "_internal/google_analytics.html" . }}
-{{- template "partials/templates/opengraph.html" . }}
-{{- template "partials/templates/twitter_cards.html" . }}
-{{- template "partials/templates/schema_json.html" . }}
+{{- partial "google_analytics.html" . }}
+{{- partial "templates/opengraph.html" . }}
+{{- partial "templates/twitter_cards.html" . }}
+{{- partial "templates/schema_json.html" . }}
 {{- end -}}
diff --git a/layouts/partials/templates/schema_json.html b/layouts/partials/templates/schema_json.html
index dc3bfd6..8a4efb4 100644
--- a/layouts/partials/templates/schema_json.html
+++ b/layouts/partials/templates/schema_json.html
@@ -85,7 +85,7 @@
     {{ (path.Join .RelPermalink .Params.cover.image ) | absURL }},
     {{- end}}
   {{- else }}
-    {{- $images := partial "partials/templates/_funcs/get-page-images" . -}}
+    {{- $images := partial "templates/_funcs/get-page-images" . -}}
     {{- with index $images 0 -}}
   "image": {{ .Permalink }},
     {{- end }}
diff --git a/layouts/partials/templates/twitter_cards.html b/layouts/partials/templates/twitter_cards.html
index 6b0d59b..a6e1d05 100644
--- a/layouts/partials/templates/twitter_cards.html
+++ b/layouts/partials/templates/twitter_cards.html
@@ -6,7 +6,7 @@
 <meta name="twitter:image" content="{{ (path.Join .RelPermalink .Params.cover.image ) | absURL }}">
 {{- end}}
 {{- else }}
-{{- $images := partial "partials/templates/_funcs/get-page-images" . -}}
+{{- $images := partial "templates/_funcs/get-page-images" . -}}
 {{- with index $images 0 -}}
 <meta name="twitter:card" content="summary_large_image">
 <meta name="twitter:image" content="{{ .Permalink }}">

Er well, I did send #1726

Yes, thank you for that. I am just not happy with how hugo handles sudden breaking changes.

same issue as well, need back to hugo 0.145.0, template system has been changed since 0.146.0

Sorry, still an issue: google-analytics.html is missing. hugo server will work with the previous commit changes, but running hugo itself on a site fails without google-analytics.html. I removed the line requiring google-analytics.html and was able to run hugo against PaperMod.

I sent #1726, though I guess there’s no CI so things aren’t exactly checked.

Er well, I did send #1726

Yes, thank you for that. I am just not happy with how hugo handles sudden breaking changes.

Yeah, I’ve been using it for a year, and I’m surprised how quickly they introduce changes that break backward compatibility. It seems like having a stable version isn’t something they prioritize 😅

Things are not settled yet and decisions are yet to be made on Hugo’s side and https://github.com/gohugoio/hugo/issues/13553 is still in progress. And we also have no backwards compatibility. One maintainer comments the patch (with a future implementation) instead of a PR. 😕

Ideally, CI would build the site itself (demo site?) with both the minimum and latest versions of hugo. Or at least, the minimum and some kind of scheduled job that runs periodically to show if the site works with the latest version, or something.

I am happy to send a PR to propose something.