forked from kataras/iris
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New feature: Fallback views. Read HISTORY.md
- Loading branch information
Showing
16 changed files
with
316 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/kataras/iris/v12" | ||
) | ||
|
||
const defaultViewName = "fallback" | ||
|
||
func main() { | ||
app := iris.New() | ||
app.RegisterView(iris.HTML("./view", ".html")) | ||
|
||
// Use the FallbackView helper Register a fallback view | ||
// filename per-party when the provided was not found. | ||
app.FallbackView(iris.FallbackView("fallback.html")) | ||
|
||
// Use the FallbackViewLayout helper to register a fallback view layout. | ||
app.FallbackView(iris.FallbackViewLayout("layout.html")) | ||
|
||
// Register a custom fallback function per-party to handle everything. | ||
// You can register more than one. If fails (returns a not nil error of ErrViewNotExists) | ||
// then it proceeds to the next registered fallback. | ||
app.FallbackView(iris.FallbackViewFunc(func(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.html", err.Data)] | ||
return err | ||
})) | ||
|
||
app.Get("/", index) | ||
|
||
app.Listen(":8080") | ||
} | ||
|
||
// Register fallback view(s) in a middleware. | ||
// func fallbackInsideAMiddleware(ctx iris.Context) { | ||
// ctx.FallbackView(...) | ||
// To remove all previous registered fallbacks, pass nil. | ||
// ctx.FallbackView(nil) | ||
// ctx.Next() | ||
// } | ||
|
||
func index(ctx iris.Context) { | ||
ctx.View("blabla.html") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<h1>Fallback view</h1> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.