Skip to content

Commit

Permalink
Merge pull request #365 from gofiber/jet-raise-error-occured-in-embed()
Browse files Browse the repository at this point in the history
[jet] raise error occured in embed()
  • Loading branch information
ReneWerner87 authored Mar 20, 2024
2 parents 230285a + b196311 commit ff49b17
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
9 changes: 7 additions & 2 deletions jet/jet.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,15 @@ func (e *Engine) Render(out io.Writer, name string, binding interface{}, layout
if err != nil {
return err
}
var renderingError error
bind.Set(e.LayoutName, func() {
err = tmpl.Execute(out, bind, nil)
renderingError = tmpl.Execute(out, bind, nil)
})
return lay.Execute(out, bind, nil)
err = lay.Execute(out, bind, nil)
if renderingError != nil {
return renderingError
}
return err
}
return tmpl.Execute(out, bind, nil)
}
Expand Down
13 changes: 13 additions & 0 deletions jet/jet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@ func Test_Layout(t *testing.T) {
require.Equal(t, expect, result)
}

func Test_Layout_Error(t *testing.T) {
t.Parallel()
engine := New("./views", ".jet")

require.NoError(t, engine.Load())

var buf bytes.Buffer
err := engine.Render(&buf, "index", map[string]interface{}{
// "Title": "Hello, World!",
}, "layouts/main")
require.NotNil(t, err)
}

func Test_Empty_Layout(t *testing.T) {
t.Parallel()
engine := New("./views", ".jet")
Expand Down

0 comments on commit ff49b17

Please sign in to comment.