1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-07 20:17:05 +00:00

New feature: Fallback views. Read HISTORY.md

This commit is contained in:
Gerasimos (Makis) Maropoulos
2021-01-24 14:08:37 +02:00
parent a2588e480d
commit 435f284815
16 changed files with 316 additions and 44 deletions

View File

@@ -217,7 +217,7 @@ func (s *AmberEngine) executeTemplateBuf(name string, binding interface{}) (stri
tmpl := s.fromCache(name)
if tmpl == nil {
s.bufPool.Put(buf)
return "", ErrNotExist{name, false}
return "", ErrNotExist{name, false, binding}
}
err := tmpl.ExecuteTemplate(buf, name, binding)
@@ -253,5 +253,5 @@ func (s *AmberEngine) ExecuteWriter(w io.Writer, filename string, layout string,
return tmpl.Execute(w, bindingData)
}
return ErrNotExist{filename, false}
return ErrNotExist{filename, false, bindingData}
}

View File

@@ -307,5 +307,5 @@ func (s *DjangoEngine) ExecuteWriter(w io.Writer, filename string, _ string, bin
return tmpl.ExecuteWriter(getPongoContext(bindingData), w)
}
return ErrNotExist{filename, false}
return ErrNotExist{filename, false, bindingData}
}

View File

@@ -235,5 +235,5 @@ func (s *HandlebarsEngine) ExecuteWriter(w io.Writer, filename string, layout st
return err
}
return ErrNotExist{fmt.Sprintf("%s (file: %s)", renderFilename, filename), false}
return ErrNotExist{fmt.Sprintf("%s (file: %s)", renderFilename, filename), false, bindingData}
}

View File

@@ -421,14 +421,14 @@ func (s *HTMLEngine) ExecuteWriter(w io.Writer, name string, layout string, bind
t := s.Templates.Lookup(name)
if t == nil {
return ErrNotExist{name, false}
return ErrNotExist{name, false, bindingData}
}
s.runtimeFuncsFor(t, name, bindingData)
if layout = getLayout(layout, s.layout); layout != "" {
lt := s.Templates.Lookup(layout)
if lt == nil {
return ErrNotExist{layout, true}
return ErrNotExist{layout, true, bindingData}
}
s.layoutFuncsFor(lt, name, bindingData)

View File

@@ -21,19 +21,7 @@ type (
)
// ErrNotExist reports whether a template was not found in the parsed templates tree.
type ErrNotExist struct {
Name string
IsLayout bool
}
// Error implements the `error` interface.
func (e ErrNotExist) Error() string {
title := "template"
if e.IsLayout {
title = "layout"
}
return fmt.Sprintf("%s '%s' does not exist", title, e.Name)
}
type ErrNotExist = context.ErrViewNotExist
// View is just a wrapper on top of the registered template engine.
type View struct{ Engine }