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
()
| 3766 | // Similarly to `viewData := ctx.Values().Get("iris.view.data")` or |
| 3767 | // `viewData := ctx.Values().Get(ctx.Application().ConfigurationReadOnly().GetViewDataContextKey())`. |
| 3768 | func (ctx *Context) GetViewData() map[string]interface{} { |
| 3769 | if v := ctx.values.Get(ctx.app.ConfigurationReadOnly().GetViewDataContextKey()); v != nil { |
| 3770 | // if pure map[string]interface{} |
| 3771 | if viewData, ok := v.(Map); ok { |
| 3772 | return viewData |
| 3773 | } |
| 3774 | |
| 3775 | // if struct, convert it to map[string]interface{} |
| 3776 | if structs.IsStruct(v) { |
| 3777 | return structs.Map(v) |
| 3778 | } |
| 3779 | } |
| 3780 | |
| 3781 | // if no values found, then return nil |
| 3782 | return nil |
| 3783 | } |
| 3784 | |
| 3785 | // FallbackViewProvider is an interface which can be registered to the `Party.FallbackView` |
| 3786 | // or `Context.FallbackView` methods to handle fallback views. |