8000 Template execution fails if no suffix is given · Issue #13601 · gohugoio/hugo · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Template execution fails if no suffix is given #13601

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

Closed
cmahnke opened this issue Apr 12, 2025 · 9 comments
Closed

Template execution fails if no suffix is given #13601

cmahnke opened this issue Apr 12, 2025 · 9 comments

Comments

@cmahnke
Copy link
cmahnke commented Apr 12, 2025

What version of Hugo are you using (hugo version)?

$ hugo version
hugo v0.146.3+extended+withdeploy darwin/arm64 BuildDate=2025-04-12T17:21:50Z VendorInfo=brew

Does this issue reproduce with the latest release?

Yes

Description

Up until 0.145 it was possible to call a partial without an file extension from another. My use case were partials
that act as output format agnostic templates function, those might return just strings.
To make it obvious that those aren't really bound to formats, I just used them without any file extension, see default-lang in the example. This wont work anymore with the new templating (at least on existing sites).

In short: Executing a template (in this case for output format HTML) that doesn't have the file suffix .html fails now.

Message

Error: error building site: render: failed to render pages: render of "/Users/cmahnke/Blogs/hugo-0.146.3/content/post/post-1.md" failed: "/Users/cmahnke/Blogs/hugo-0.146.3/layouts/_default/single.html:4:32": execute of template failed: template: single.html:4:32: executing "main" at <partialCached "functions/i18n/default-lang" .>: error calling partialCached: template: :1:29: executing "_partials/functions/i18n/default-lang" at <.Arg>: can't evaluate field Arg in type *hugolib.pageState

Example

https://github.com/cmahnke/hugo-13601

Updates

  • It seems to be not an issue of template resolution, since there issn't a message that the template wasn't found.
  • Since it used to work with 0.145.0 it's related to backwards compatibility similar to Calls to the template function are not backwards compatible in some cases #13599.
  • Renaming the template to have a suffix (.html) makes it work, even if I don't change the caller. My expectation would have been that this should fail, since the template file don't actually exist under the given file name.
@cmahnke cmahnke changed the title Template resolution fails if no suffix is given Template execution fails if no suffix is given Apr 13, 2025
@jmooring
Copy link
Member

Executing a template (in this case for output format HTML) that doesn't have the file suffix .html fails now

I was not able to reproduce this:

git clone --single-branch -b hugo-github-issue-13601 https://github.com/jmooring/hugo-testing hugo-github-issue-13601
cd hugo-github-issue-13601
hugo

In the example above, single.html calls partials/foo.html which calls partials/bar... no problems.

But the behavior has changed...

v0.145.0

template path template call notes
layouts/partials/foo.html {{ partial "foo.html" . }} this works
layouts/partials/foo.html {{ partial "foo" . }} this works (provides backwards compatibility)
layouts/partials/foo {{ partial "foo.html" . }} this throws an error (template not found)
layouts/partials/foo {{ partial "foo" . }} this works

v0.146.0

template path template call notes
layouts/partials/foo.html {{ partial "foo.html" . }} this works
layouts/partials/foo.html {{ partial "foo" . }} this works (provides backwards compatibility)
layouts/partials/foo {{ partial "foo.html" . }} this works (new behavior)
layouts/partials/foo {{ partial "foo" . }} this works

You get the same result in v0.146.0 using layouts/_partials instead of layouts/partials.

As you know, partial templates are agnostic with respect to language and output format. So if you needed both HTML and JSON:

layouts/
└── _partials/
    ├── foo.html
    └── foo.json

{{ partial "foo.html" . }}
{{ partial "foo.json" . }}

If you have a partial template you intended to use with all output formats, and you want to visually indicate your intent, use a different extension, the value of which is irrelevant.

layouts/
└── _partials/
    ├── foo.agnostic <-- extension is irrelevant
    ├── foo.html
    └── foo.json

{{ partial "foo.html" . }}
{{ partial "foo.json" . }}
{{ partial "foo.agnositic" . }}

@jmooring
Copy link
Member

@cmahnke Also, your test site worked fine for me:

Image

Note the "en" at the end.

@cmahnke
Copy link
Author
cmahnke commented Apr 14, 2025

Thanks @jmooring for having a look. I still see the issue but get what you mean, it's very strage:
Running:

seq 5 |xargs -Iz hugo

gives:

Start building sites … 
hugo v0.146.3+extended+withdeploy darwin/arm64 BuildDate=2025-04-12T17:21:50Z VendorInfo=brew


                   | EN  
-------------------+-----
  Pages            | 10  
  Paginator pages  |  0  
  Non-page files   |  0  
  Static files     |  0  
  Processed images |  0  
  Aliases          |  0  
  Cleaned          |  0  

Total in 9 ms
Start building sites … 
hugo v0.146.3+extended+withdeploy darwin/arm64 BuildDate=2025-04-12T17:21:50Z VendorInfo=brew

Total in 8 ms
Error: error building site: render: failed to render pages: render of "/Users/cmahnke/Blogs/hugo-0.146.3/content/post/post-1.md" failed: "/Users/cmahnke/Blogs/hugo-0.146.3/layouts/_default/single.html:4:32": execute of template failed: template: single.html:4:32: executing "main" at <partialCached "functions/i18n/default-lang" .>: error calling partialCached: template: :1:29: executing "_partials/functions/i18n/default-lang" at <.Arg>: can't evaluate field Arg in type *hugolib.pageState
Start building sites … 
hugo v0.146.3+extended+withdeploy darwin/arm64 BuildDate=2025-04-12T17:21:50Z VendorInfo=brew

Total in 8 ms
Error: error building site: render: failed to render pages: render of "/Users/cmahnke/Blogs/hugo-0.146.3/content/post/post-1.md" failed: "/Users/cmahnke/Blogs/hugo-0.146.3/layouts/_default/single.html:4:32": execute of template failed: template: single.html:4:32: executing "main" at <partialCached "functions/i18n/default-lang" .>: error calling partialCached: template: :1:29: executing "_partials/functions/i18n/default-lang" at <.Arg>: can't evaluate field Arg in type *hugolib.pageState
Start building sites … 
hugo v0.146.3+extended+withdeploy darwin/arm64 BuildDate=2025-04-12T17:21:50Z VendorInfo=brew

Total in 8 ms
Error: error building site: render: failed to render pages: render of "/Users/cmahnke/Blogs/hugo-0.146.3/content/post/post-1.md" failed: "/Users/cmahnke/Blogs/hugo-0.146.3/layouts/_default/single.html:4:32": execute of template failed: template: single.html:4:32: executing "main" at <partialCached "functions/i18n/default-lang" .>: error calling partialCached: template: :1:29: executing "_partials/functions/i18n/default-lang" at <.Arg>: can't evaluate field Arg in type *hugolib.pageState
Start building sites … 
hugo v0.146.3+extended+withdeploy darwin/arm64 BuildDate=2025-04-12T17:21:50Z VendorInfo=brew

Total in 8 ms
Error: error building site: render: failed to render pages: render of "/Users/cmahnke/Blogs/hugo-0.146.3/content/post/post-1.md" failed: "/Users/cmahnke/Blogs/hugo-0.146.3/layouts/_default/single.html:4:32": execute of template failed: template: single.html:4:32: executing "main" at <partialCached "functions/i18n/default-lang" .>: error calling partialCached: template: :1:29: executing "_partials/functions/i18n/default-lang" at <.Arg>: can't evaluate field Arg in type *hugolib.pageState

@jmooring
Copy link
Member
jmooring commented Apr 14, 2025

OK, the failure is intermittent when the partial file does not have an extension, but works every time when it has an extension. So... give it an extension?

This is related to the return statement.

@cmahnke
Copy link
Author
cmahnke commented Apr 14, 2025

Well, yes, already did that. But it's still an strange result, maybe a race condition, that should be addressed. Or at least looked into. It might be an indicator for broken logic. But it has a lower priority right now.
Thanks!

Just in case anyone else get's a:

at <.Arg>: can't evaluate field Arg in type *hugolib.pageState

@cmahnke
Copy link
Author
cmahnke commented Apr 14, 2025

@bep
Copy link
Member
bep commented Apr 14, 2025

I will have a look at this.

@istr
Copy link
istr commented Apr 14, 2025

For what it is worth - I had the same problem, so I was able to reproduce it independently.
Thanks a lot @bep for the extremely quick fix - I will undo the changes (adding an .html extension) in my case (which was exactly the same use case as @cmahnke's).

Copy link
github-actions bot commented May 6, 2025

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

No branches or pull requests

4 participants
0