1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-10 21:45:57 +00:00

add support for fs.FS, embed.FS (in addition of string and http.FileSystem) for i18n locales and view engine's templates

This commit is contained in:
Gerasimos (Makis) Maropoulos
2022-09-25 20:40:56 +03:00
parent 4cd0621018
commit 512ed6ffc0
29 changed files with 276 additions and 202 deletions

View File

@@ -9,6 +9,6 @@
{{ template "content" .}}
<h4>Copyright &copy; 2020 Admin</h4>
<h4>Copyright &copy; 2022 Admin</h4>
</body>
</html>

View File

@@ -1,12 +1,12 @@
<html>
<head>
<title>Layout</title>
</head>
<body>
<h1>This is the global layout</h1>
<br />
<!-- Render the current template here -->
{{ yield }}
</body>
</html>
<html>
<head>
<title>Layout</title>
</head>
<body>
<h1>This is the global layout</h1>
<br />
<!-- Render the current template here -->
{{ yield }}
</body>
</html>

View File

@@ -1,12 +1,12 @@
<html>
<head>
<title>my Layout</title>
</head>
<body>
<h1>This is the layout for the /my/ and /my/other routes only</h1>
<br />
<!-- Render the current template here -->
{{ yield }}
</body>
</html>
<html>
<head>
<title>my Layout</title>
</head>
<body>
<h1>This is the layout for the /my/ and /my/other routes only</h1>
<br />
<!-- Render the current template here -->
{{ yield }}
</body>
</html>

View File

@@ -1,7 +1,7 @@
<div style="background-color: black; color: blue">
<h1>Page 1 {{ greet "iris developer"}}</h1>
{{ render "partials/page1_partial1.html"}}
</div>
<div style="background-color: black; color: blue">
<h1>Page 1 {{ greet "iris developer"}}</h1>
{{ render "partials/page1_partial1.html"}}
</div>

View File

@@ -1,3 +1,3 @@
<div style="background-color: white; color: red">
<h1>Page 1's Partial 1</h1>
</div>
<div style="background-color: white; color: red">
<h1>Page 1's Partial 1</h1>
</div>

View File

@@ -7,13 +7,14 @@ import (
"github.com/kataras/iris/v12/x/errors"
)
//go:embed templates/*
var embeddedTemplatesFS embed.FS
//go:embed embedded/*
var embeddedFS embed.FS
func main() {
app := iris.New()
tmpl := iris.HTML(embeddedTemplatesFS, ".html")
tmpl := iris.HTML(embeddedFS, ".html").RootDir("embedded/templates")
tmpl.Layout("layouts/layout.html")
tmpl.AddFunc("greet", func(s string) string {
return "Greetings " + s + "!"