mirror of
https://github.com/kataras/iris.git
synced 2025-02-09 02:34:55 +01:00
add part function in html.go
layout.html <head> {{ part "css" }} </head> home/index.html {{ define "home/index-css"}} <link rel="stylesheet" type="text/css" href="/public/css/home/index.css" /> {{ end }} in html/temple the defined block is global variable, so the way of "{{ block "css" }}" in layout and "{{ define "css"}}{{end}}" in home/index.html and home/about.html just one definition work, others will be over coved。 No use!!! This part function like extend the block in layout. Former-commit-id: c3e26a8227808cf2d1dc7121bcffe1a98ce3e678
This commit is contained in:
parent
8950ae7bb9
commit
de5be10955
12
view/html.go
12
view/html.go
|
@ -44,6 +44,9 @@ var emptyFuncs = template.FuncMap{
|
||||||
"yield": func() (string, error) {
|
"yield": func() (string, error) {
|
||||||
return "", fmt.Errorf("yield was called, yet no layout defined")
|
return "", fmt.Errorf("yield was called, yet no layout defined")
|
||||||
},
|
},
|
||||||
|
"part": func() (string, error) {
|
||||||
|
return "", fmt.Errorf("block was called, yet no layout defined")
|
||||||
|
},
|
||||||
"partial": func() (string, error) {
|
"partial": func() (string, error) {
|
||||||
return "", fmt.Errorf("block was called, yet no layout defined")
|
return "", fmt.Errorf("block was called, yet no layout defined")
|
||||||
},
|
},
|
||||||
|
@ -389,6 +392,15 @@ func (s *HTMLEngine) layoutFuncsFor(name string, binding interface{}) {
|
||||||
// Return safe HTML here since we are rendering our own template.
|
// Return safe HTML here since we are rendering our own template.
|
||||||
return template.HTML(buf.String()), err
|
return template.HTML(buf.String()), err
|
||||||
},
|
},
|
||||||
|
"part": func(partName string) (template.HTML, error) {
|
||||||
|
nameTemp := strings.Replace(name, ".html", "", -1)
|
||||||
|
fullPartName := fmt.Sprintf("%s-%s", nameTemp, partName)
|
||||||
|
buf, err := s.executeTemplateBuf(fullPartName, binding)
|
||||||
|
if err != nil {
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
return template.HTML(buf.String()), err
|
||||||
|
},
|
||||||
"current": func() (string, error) {
|
"current": func() (string, error) {
|
||||||
return name, nil
|
return name, nil
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue
Block a user