mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-15 21:06:39 +08:00
minor fixes for template_storage
This commit is contained in:
parent
675af529c9
commit
bb0eff82a6
@ -7,4 +7,4 @@
|
|||||||
<body>
|
<body>
|
||||||
{{block "body" .}} {{end}}
|
{{block "body" .}} {{end}}
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -16,4 +16,4 @@ func main() {
|
|||||||
|
|
||||||
func render(c *gin.Context) {
|
func render(c *gin.Context) {
|
||||||
c.HTML(200, c.Request.URL.Path, gin.H{})
|
c.HTML(200, c.Request.URL.Path, gin.H{})
|
||||||
}
|
}
|
||||||
|
@ -4,4 +4,4 @@
|
|||||||
|
|
||||||
{{define "body"}}
|
{{define "body"}}
|
||||||
<a href="/blocks2/">Go to blocks 2</a>
|
<a href="/blocks2/">Go to blocks 2</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
@ -4,4 +4,4 @@
|
|||||||
|
|
||||||
{{define "body"}}
|
{{define "body"}}
|
||||||
<a href="/">Go to blocks 1</a>
|
<a href="/">Go to blocks 1</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
@ -14,20 +14,20 @@ type TemplateStorage struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t TemplateStorage) Instance(name string, data interface{}) Render {
|
func (t TemplateStorage) Instance(name string, data interface{}) Render {
|
||||||
return HTMLwithBlock{
|
return HTMLWithBlock{
|
||||||
Template: t.Storage[name],
|
Template: t.Storage[name],
|
||||||
Name: name,
|
Name: name,
|
||||||
Data: data,
|
Data: data,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type HTMLwithBlock struct {
|
type HTMLWithBlock struct {
|
||||||
Template *template.Template
|
Template *template.Template
|
||||||
Name string
|
Name string
|
||||||
Data interface{}
|
Data interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r HTMLwithBlock) Render(w http.ResponseWriter) error {
|
func (r HTMLWithBlock) Render(w http.ResponseWriter) error {
|
||||||
writeContentType(w, htmlContentType)
|
writeContentType(w, htmlContentType)
|
||||||
return r.Template.Execute(w, r.Data)
|
return r.Template.Execute(w, r.Data)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user