Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow for nested layouts, (multiple nested embed tags) #287

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading