1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-23 11:56:00 +00:00

builtin html template functions changes

This commit is contained in:
Gerasimos (Makis) Maropoulos
2022-12-13 01:37:15 +02:00
parent abeae40e60
commit 1ea5cd58be
115 changed files with 472 additions and 230 deletions

View File

@@ -44,7 +44,10 @@ func main() {
// Bind: {{.message}} with "Hello world!"
ctx.ViewData("message", "Hello world!")
// Render template file: ./views/hello.html
ctx.View("hello.html")
if err := ctx.View("hello.html"); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
return
}
})
// Method: GET
@@ -85,10 +88,10 @@ func main() {
// builtin template funcs are:
//
// - {{ urlpath "mynamedroute" "pathParameter_ifneeded" }}
// - {{ render "header.html" }}
// - {{ render_r "header.html" }} // partial relative path to current page
// - {{ yield }}
// - {{ current }}
// - {{ render "header.html" . }}
// - {{ render_r "header.html" . }} // partial relative path to current page
// - {{ yield . }}
// - {{ current . }}
// register a custom template func.
tmpl.AddFunc("greet", func(s string) string {
@@ -106,7 +109,10 @@ func main() {
func hi(ctx iris.Context) {
// render the template file "./templates/hi.html"
ctx.View("hi.html")
if err := ctx.View("hi.html"); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
return
}
}
```
@@ -150,7 +156,10 @@ type page struct {
func hi(ctx iris.Context) {
// {{.Page.Title}} and {{Page.Name}}
ctx.ViewData("Page", page{Title: "Hi Page", Name: "iris"})
ctx.View("hi.html")
if err := ctx.View("hi.html"); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
return
}
}
```