Skip to content

Commit

Permalink
allow for nested layouts, (multiple embed tags)
Browse files Browse the repository at this point in the history
allow for nested layouts, (multiple embed tags)
cases where nested layouts (embed) are required:  
post.django -> layout.django -> index.django
renders post.django with layout = {"layout","index"}
  • Loading branch information
ovresko authored Sep 3, 2023
1 parent e28361c commit edbc98f
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions django/django.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,17 +195,22 @@ func (e *Engine) Render(out io.Writer, name string, binding interface{}, layout
if err != nil {
return err
}
if len(layout) > 0 && layout[0] != "" {
if bind == nil {
bind = make(map[string]interface{}, 1)
}
// allow for nested layouts, (multiple embed tags)
// cases where nested layouts (embed) are required: post.django -> layout.django -> index.django
if bind == nil {
bind = make(map[string]interface{}, 1)
}
for _, alayout := range layout {
lay := e.Templates[alayout]
bind[e.LayoutName] = parsed
lay := e.Templates[layout[0]]
parsed, err = lay.Execute(bind)

if lay == nil {
return fmt.Errorf("LayoutName %s does not exist", layout[0])
return fmt.Errorf("LayoutName %s does not exist", alayout)
}
return lay.ExecuteWriter(bind, out)
}

if _, err = out.Write([]byte(parsed)); err != nil {
return err
}
Expand Down

0 comments on commit edbc98f

Please sign in to comment.