mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 10:41:03 +01:00
minor: fix Context.ViewData ignored when nil is passed as view data on Context.View method
This commit is contained in:
parent
600eb645df
commit
6ee69ffd1c
|
@ -4,6 +4,7 @@ import "github.com/kataras/iris/v12"
|
|||
|
||||
func main() {
|
||||
app := iris.New()
|
||||
app.Logger().SetLevel("debug")
|
||||
|
||||
// Init the handlebars engine
|
||||
engine := iris.Handlebars("./templates", ".html").Reload(true)
|
||||
|
@ -27,6 +28,21 @@ func main() {
|
|||
ctx.View("example.html", viewData)
|
||||
})
|
||||
|
||||
/* See context-view-data example: Set data through one or more middleware
|
||||
app.Get("/view_data", func(ctx iris.Context) {
|
||||
ctx.ViewData("author", map[string]string{"firstName": "Jean", "lastName": "Valjean"})
|
||||
ctx.ViewData("body", "Life is difficult")
|
||||
ctx.ViewData("comments", []iris.Map{{
|
||||
"author": map[string]string{"firstName": "Marcel", "lastName": "Beliveau"},
|
||||
"body": "LOL!",
|
||||
}})
|
||||
|
||||
ctx.Next()
|
||||
}, func(ctx iris.Context) {
|
||||
ctx.View("example.html")
|
||||
})
|
||||
*/
|
||||
|
||||
// Read more about its syntax at:
|
||||
// https://github.com/aymerick/raymond and
|
||||
// https://handlebarsjs.com/guide
|
||||
|
|
|
@ -2792,7 +2792,7 @@ func (ctx *Context) View(filename string, optionalViewModel ...interface{}) erro
|
|||
layout := ctx.values.GetString(cfg.GetViewLayoutContextKey())
|
||||
|
||||
var bindingData interface{}
|
||||
if len(optionalViewModel) > 0 {
|
||||
if len(optionalViewModel) > 0 && optionalViewModel[0] != nil {
|
||||
// a nil can override the existing data or model sent by `ViewData`.
|
||||
bindingData = optionalViewModel[0]
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue
Block a user