hugolib: Return error from .Render when template not found

Closes #15052
This commit is contained in:
Joe Mooring
2026-06-22 20:04:26 -07:00
committed by Bjørn Erik Pedersen
parent d15baf53a9
commit fe06735214
3 changed files with 20 additions and 2 deletions
+1 -1
View File
@@ -114,7 +114,7 @@ func (pco *pageContentOutput) Render(ctx context.Context, layout ...string) (tem
}
if !found {
return "", nil
return "", fmt.Errorf("template %q not found", layout[0])
}
// Make sure to send the *pageState and not the *pageContentOutput to the template.
+18
View File
@@ -2055,3 +2055,21 @@ disableKinds = ["taxonomy", "term"]
}
}
}
// 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 := TestE(t, files)
b.Assert(err, qt.ErrorMatches, `.*template "view_bar" not found.*`)
}