Description
The issue is that in jetVarMap
it assumes that a nil binding
should result in a nil jet.VarMap
.
Lines 233 to 237 in c4b2c7e
But if a layout is specified, it is then used to set a function and panics:
Lines 219 to 229 in c4b2c7e
This could be solved either by replacing var bind jet.VarMap
with bind := make(jet.VarMap)
or by checking if bind
is nil (and make
ing it if not) in Render
right after if len(layout) > 0 {
.
// var bind jet.VarMap
bind := make(jet.VarMap)
Or in Render
bind := jetVarMap(binding)
if len(layout) > 0 {
if bind == nil {
bind = make(jet.VarMap)
}
lay, err := e.Templates.GetTemplate(layout[0])
if err != nil {
return err
}
bind.Set(e.layout, func() {
_ = tmpl.Execute(out, bind, nil)
})
return lay.Execute(out, bind, nil)
}
I would send a pull request, but I'm not sure if it matters to you which way it is fixed. I would think it would be much clearer to put it in jetVarMap and get rid of the other calls to make
there, but I guess there was a reason to not do that in the first place.
The work around is for the caller of Render
to just specify an empty jet.VarMap
or fiber.Map
but that is not obvious and panic
ing from forgetting is not great.