-
Notifications
You must be signed in to change notification settings - Fork 56
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
| func jetVarMap(binding interface{}) jet.VarMap { | |
| var bind jet.VarMap | |
| if binding == nil { | |
| return bind | |
| } |
But if a layout is specified, it is then used to set a function and panics:
Lines 219 to 229 in c4b2c7e
| bind := jetVarMap(binding) | |
| if len(layout) > 0 { | |
| 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) | |
| } |
This could be solved either by replacing var bind jet.VarMap with bind := make(jet.VarMap) or by checking if bind is nil (and makeing 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 panicing from forgetting is not great.