1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-18 02:17:05 +00:00

Ability to register a view engine per group of routes or for the current a chain of handlers

Example at: https://github.com/kataras/iris/tree/master/_examples/view/context-view-engine
This commit is contained in:
Gerasimos (Makis) Maropoulos
2020-08-05 19:34:55 +03:00
parent b363492cca
commit 5d480dc801
22 changed files with 282 additions and 66 deletions

View File

@@ -1022,6 +1022,24 @@ func (api *APIBuilder) OnAnyErrorCode(handlers ...context.Handler) (routes []*Ro
return
}
// RegisterView registers and loads a view engine middleware for that group of routes.
// It overrides any of the application's root registered view engines.
// To register a view engine per handler chain see the `Context.ViewEngine` instead.
// Read `Configuration.ViewEngineContextKey` documentation for more.
func (api *APIBuilder) RegisterView(viewEngine context.ViewEngine) {
if err := viewEngine.Load(); err != nil {
api.errors.Add(err)
return
}
api.Use(func(ctx *context.Context) {
ctx.ViewEngine(viewEngine)
ctx.Next()
})
// Note (@kataras): It does not return the Party in order
// to keep the iris.Application a compatible Party.
}
// Layout overrides the parent template layout with a more specific layout for this Party.
// It returns the current Party.
//