mirror of
https://github.com/kataras/iris.git
synced 2025-12-17 18:07:01 +00:00
New feature: Fallback views. Read HISTORY.md
This commit is contained in:
@@ -1491,6 +1491,26 @@ func (api *APIBuilder) RegisterView(viewEngine context.ViewEngine) {
|
||||
// to keep the iris.Application a compatible Party.
|
||||
}
|
||||
|
||||
// FallbackView registers one or more fallback views for a template or a template layout.
|
||||
// Usage:
|
||||
// FallbackView(iris.FallbackView("fallback.html"))
|
||||
// FallbackView(iris.FallbackViewLayout("layouts/fallback.html"))
|
||||
// OR
|
||||
// FallbackView(iris.FallbackViewFunc(ctx iris.Context, err iris.ErrViewNotExist) error {
|
||||
// err.Name is the previous template name.
|
||||
// err.IsLayout reports whether the failure came from the layout template.
|
||||
// err.Data is the template data provided to the previous View call.
|
||||
// [...custom logic e.g. ctx.View("fallback", err.Data)]
|
||||
// })
|
||||
func (api *APIBuilder) FallbackView(provider context.FallbackViewProvider) {
|
||||
handler := func(ctx *context.Context) {
|
||||
ctx.FallbackView(provider)
|
||||
ctx.Next()
|
||||
}
|
||||
api.Use(handler)
|
||||
api.UseError(handler)
|
||||
}
|
||||
|
||||
// Layout overrides the parent template layout with a more specific layout for this Party.
|
||||
// It returns the current Party.
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user