Skip to content

Commit

Permalink
Return error when .Render is invoked without arg
Browse files Browse the repository at this point in the history
Fixes #11243
  • Loading branch information
bep committed Jul 13, 2023
1 parent f1886f8 commit 4da672a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions hugolib/page__per_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,9 @@ func (p *pageContentOutput) RenderWithTemplateInfo(ctx context.Context, info tpl
}

func (p *pageContentOutput) Render(ctx context.Context, layout ...string) (template.HTML, error) {
if len(layout) == 0 {
return "", errors.New("no layout given")
}
templ, found, err := p.p.resolveTemplate(layout...)
if err != nil {
return "", p.p.wrapError(err)
Expand Down
22 changes: 22 additions & 0 deletions hugolib/page_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1983,3 +1983,25 @@ title: "p2"
b.Assert(identity.HashString(p1), qt.Not(qt.Equals), identity.HashString(p2))
b.Assert(identity.HashString(sites[0]), qt.Not(qt.Equals), identity.HashString(sites[1]))
}

// Issue #11243
func TestRenderWithoutArgument(t *testing.T) {
t.Parallel()

files := `
-- hugo.toml --
-- layouts/index.html --
{{ .Render }}
`

b, err := NewIntegrationTestBuilder(
IntegrationTestConfig{
T: t,
TxtarString: files,
Running: true,
},
).BuildE()

b.Assert(err, qt.IsNotNil)

}

0 comments on commit 4da672a

Please sign in to comment.