mirror of
https://github.com/kataras/iris.git
synced 2025-12-20 03:17:04 +00:00
builtin html template functions changes
This commit is contained in:
@@ -100,7 +100,10 @@ func profileByUsername(ctx iris.Context) {
|
||||
ctx.ViewData("Username", username)
|
||||
// renders "./views/user/profile.html"
|
||||
// with {{ .Username }} equals to the username dynamic path parameter.
|
||||
ctx.View("user/profile.html")
|
||||
if err := ctx.View("user/profile.html"); err != nil {
|
||||
ctx.HTML("<h3>%s</h3>", err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func getUserByID(ctx iris.Context) {
|
||||
@@ -122,5 +125,8 @@ func createUser(ctx iris.Context) {
|
||||
// renders "./views/user/create_verification.html"
|
||||
// with {{ . }} equals to the User object, i.e {{ .Username }} , {{ .Firstname}} etc...
|
||||
ctx.ViewData("", user)
|
||||
ctx.View("user/create_verification.html")
|
||||
if err := ctx.View("user/create_verification.html"); err != nil {
|
||||
ctx.HTML("<h3>%s</h3>", err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,9 +28,12 @@ func newApp() *iris.Application {
|
||||
}
|
||||
|
||||
func handleNotFoundTestSubdomain(ctx iris.Context) {
|
||||
ctx.View("error.html", iris.Map{
|
||||
if err := ctx.View("error.html", iris.Map{
|
||||
"ErrorCode": ctx.GetStatusCode(),
|
||||
})
|
||||
}); err != nil {
|
||||
ctx.HTML("<h3>%s</h3>", err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func testIndex(ctx iris.Context) {
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
<h1>Oups, you've got an error!</h1>
|
||||
{{ if .ErrorCode }}
|
||||
{{ $tmplName := print "partials/" .ErrorCode ".html"}}
|
||||
{{ render $tmplName }}
|
||||
{{ render $tmplName . }}
|
||||
{{ else }}
|
||||
{{ render "partials/500.html" }}
|
||||
{{ render "partials/500.html" . }}
|
||||
{{ end }}
|
||||
</div>
|
||||
|
||||
@@ -7,6 +7,6 @@
|
||||
<h1>This is the global layout</h1>
|
||||
<br />
|
||||
<!-- Render the current template here -->
|
||||
{{ yield }}
|
||||
{{ yield . }}
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -5,6 +5,6 @@
|
||||
</head>
|
||||
<body>
|
||||
<!-- Render the current template here -->
|
||||
{{ yield }}
|
||||
{{ yield . }}
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -98,5 +98,8 @@ func testError(v string) iris.Handler {
|
||||
}
|
||||
|
||||
func testView(ctx iris.Context) {
|
||||
ctx.View("index.html")
|
||||
if err := ctx.View("index.html"); err != nil {
|
||||
ctx.HTML("<h3>%s</h3>", err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user