mirror of
https://github.com/kataras/iris.git
synced 2025-12-18 18:37:05 +00:00
directly support embed.FS and fs.FS on view engines
This commit is contained in:
@@ -1,15 +1,19 @@
|
||||
package main
|
||||
|
||||
import "github.com/kataras/iris/v12"
|
||||
import (
|
||||
"embed"
|
||||
|
||||
"github.com/kataras/iris/v12"
|
||||
"github.com/kataras/iris/v12/x/errors"
|
||||
)
|
||||
|
||||
//go:embed templates/*
|
||||
var embeddedTemplatesFS embed.FS
|
||||
|
||||
func main() {
|
||||
app := iris.New()
|
||||
|
||||
// $ go install github.com/go-bindata/go-bindata/v3/go-bindata@latest
|
||||
// $ go-bindata -fs -prefix "templates" ./templates/...
|
||||
// $ go run .
|
||||
// html files are not used, you can delete the folder and run the example.
|
||||
tmpl := iris.HTML(AssetFile(), ".html")
|
||||
tmpl := iris.HTML(embeddedTemplatesFS, ".html")
|
||||
tmpl.Layout("layouts/layout.html")
|
||||
tmpl.AddFunc("greet", func(s string) string {
|
||||
return "Greetings " + s + "!"
|
||||
@@ -19,8 +23,8 @@ func main() {
|
||||
|
||||
app.Get("/", func(ctx iris.Context) {
|
||||
if err := ctx.View("page1.html"); err != nil {
|
||||
ctx.StatusCode(iris.StatusInternalServerError)
|
||||
ctx.Writef(err.Error())
|
||||
errors.InvalidArgument.Err(ctx, err)
|
||||
return
|
||||
}
|
||||
})
|
||||
|
||||
@@ -28,8 +32,8 @@ func main() {
|
||||
app.Get("/nolayout", func(ctx iris.Context) {
|
||||
ctx.ViewLayout(iris.NoLayout)
|
||||
if err := ctx.View("page1.html"); err != nil {
|
||||
ctx.StatusCode(iris.StatusInternalServerError)
|
||||
ctx.Writef(err.Error())
|
||||
errors.InvalidArgument.Err(ctx, err)
|
||||
return
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user