1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-08 20:41:57 +00:00

add quicktemplate example. Iris + Quicktemplate made easy 👍

Former-commit-id: b17fb21d8c1d5a73f9f9170f49ae0527870377a1
This commit is contained in:
hiveminded
2017-07-18 21:17:23 +03:00
parent 093d087a68
commit feb1d264c0
17 changed files with 545 additions and 13 deletions

View File

@@ -22,6 +22,7 @@ import (
"strings"
"time"
"github.com/fatih/structs"
"github.com/microcosm-cc/bluemonday"
"github.com/monoculum/formam"
"github.com/russross/blackfriday"
@@ -486,6 +487,17 @@ type Context interface {
// Example: https://github.com/kataras/iris/tree/master/_examples/view/context-view-data/
ViewData(key string, value interface{})
// GetViewData returns the values registered by `context#ViewData`.
// The return value is `map[string]interface{}`, this means that
// if a custom struct registered to ViewData then this function
// will try to parse it to map, if failed then the return value is nil
// A check for nil is always a good practise if different
// kind of values or no data are registered via `ViewData`.
//
// Similarly to `viewData := ctx.Values().Get("iris.viewData")` or
// `viewData := ctx.Values().Get(ctx.Application().ConfigurationReadOnly().GetViewDataContextKey())`.
GetViewData() map[string]interface{}
// View renders templates based on the adapted view engines.
// First argument accepts the filename, relative to the view engine's Directory,
// i.e: if directory is "./templates" and want to render the "./templates/users/index.html"
@@ -1626,6 +1638,43 @@ func (ctx *context) ViewData(key string, value interface{}) {
}
}
// GetViewData returns the values registered by `context#ViewData`.
// The return value is `map[string]interface{}`, this means that
// if a custom struct registered to ViewData then this function
// will try to parse it to map, if failed then the return value is nil
// A check for nil is always a good practise if different
// kind of values or no data are registered via `ViewData`.
//
// Similarly to `viewData := ctx.Values().Get("iris.viewData")` or
// `viewData := ctx.Values().Get(ctx.Application().ConfigurationReadOnly().GetViewDataContextKey())`.
func (ctx *context) GetViewData() map[string]interface{} {
viewDataContextKey := ctx.Application().ConfigurationReadOnly().GetViewDataContextKey()
v := ctx.Values().Get(viewDataContextKey)
// if no values found, then return nil
if v == nil {
return nil
}
// if struct, convert it to map[string]interface{}
if structs.IsStruct(v) {
return structs.Map(v)
}
// if pure map[string]interface{}
if viewData, ok := v.(map[string]interface{}); ok {
return viewData
}
// if context#Map
if viewData, ok := v.(Map); ok {
return viewData
}
// if failure, then return nil
return nil
}
// View renders templates based on the adapted view engines.
// First argument accepts the filename, relative to the view engine's Directory,
// i.e: if directory is "./templates" and want to render the "./templates/users/index.html"