Skip to content

hugolib: Throw error when Render method is unable to find specified templateΒ #15052

Closed

Description

@jmooring

Currently, when you invoke .Page.Render and pass it the name of a non-existent template, the method returns an empty string without warning or error. This isn't anything new; Hugo has behaved this way since 0.54.0, and probably earlier.

There may be a good reason for the existing behavior, but it was surprising to me.

Relevant code:

func (pco *pageContentOutput) Render(ctx context.Context, layout ...string) (template.HTML, error) {
if len(layout) == 0 {
return "", errors.New("no layout given")
}
templ, found, err := pco.po.p.resolveTemplate(layout...)
if err != nil {
return "", pco.po.p.wrapError(err)
}
if !found {
return "", nil
}
// Make sure to send the *pageState and not the *pageContentOutput to the template.
res, err := executeToString(ctx, pco.po.p.s.GetTemplateStore(), templ, pco.po.p)
if err != nil {
return "", pco.po.p.wrapError(fmt.Errorf("failed to execute template %s: %w", templ.Name(), err))
}
return template.HTML(res), nil
}

Integration test:

// See issue 15052.
func TestRenderViewNotFound(t *testing.T) {
	t.Parallel()

	files := `
-- hugo.toml --
disableKinds = ['page','rss','section','sitemap','taxonomy','term']
-- layouts/home.html --
{{ .Render "view_foo" }}
{{ .Render "view_bar" }}
-- layouts/view_foo.html --
foo
`

	b, err := hugolib.TestE(t, files)
	b.Assert(err, qt.IsNotNil) // fails (no error is thrown)
}

Reference: https://discourse.gohugo.io/t/silent-error-with-render-function-in-v0-163-2-extended-withdeploy/57290/7

Activity

  1. added this to the v0.164.0 milestone on Jun 22, 2026
  2. added a commit that references this issue on Jun 23, 2026
    e921aa8
  3. self-assigned this
    on Jun 24, 2026
  4. added a commit that references this issue on Jun 25, 2026
    fe06735
  5. github-actions commented on Sep 2, 2026

    @github-actions

    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.

  6. locked as resolved and limited conversation to collaborators on Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions