Skip to content

Commit

Permalink
Merge pull request #21 from ansrivas/as/fixes-20
Browse files Browse the repository at this point in the history
added funcmap to default context
  • Loading branch information
Fenny committed Jun 17, 2020
2 parents 6daca97 + d7a3de9 commit 18838e8
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions django/django.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,8 @@ func (e *Engine) Load() error {

e.Templates = make(map[string]*pongo2.Template)
// Set template settings
set := pongo2.NewSet("", pongo2.DefaultLoader)
set.Globals = e.funcmap
pongo2.SetAutoescape(false)
pongo2.DefaultSet.Globals.Update(e.funcmap)

// Loop trough each directory and register template files
walkFn := func(path string, info os.FileInfo, err error) error {
Expand Down Expand Up @@ -184,7 +183,7 @@ func getPongoBinding(binding interface{}) pongo2.Context {
return nil
}

// Execute will render the template by name
// Render will render the template by name
func (e *Engine) Render(out io.Writer, template string, binding interface{}, layout ...string) error {
if e.reload {
if err := e.Load(); err != nil {
Expand All @@ -195,6 +194,7 @@ func (e *Engine) Render(out io.Writer, template string, binding interface{}, lay
if !ok {
return fmt.Errorf("template %s does not exist", template)
}

bind := getPongoBinding(binding)
parsed, err := tmpl.Execute(bind)
if err != nil {
Expand Down

0 comments on commit 18838e8

Please sign in to comment.