File: view/template_html_2/main.go
~~~
package main
import (
"github.com/kataras/iris"
)
func main() {
app := iris.New()
tmpl := iris.HTML("./templates", ".html")
tmpl.Layout("layouts/layout.html")
tmpl.AddFunc("greet", func(s string) string {
return "Greetings " + s + "!"
})
app.RegisterView(tmpl)
app.Get("/", func(ctx iris.Context) {
if err := ctx.View("page1.html"); err != nil {
ctx.StatusCode(iris.StatusInternalServerError)
ctx.Writef(err.Error())
}
})
// remove the layout for a specific route
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())
}
})
// 设置派对的布局,。布局应该是任何Get或其他Handle派对的方法之前
my := app.Party("/my").Layout("layouts/mylayout.html")
{ // 这两个都将使用layouts / mylayout.html作为其布局.
my.Get("/", func(ctx iris.Context) {
ctx.View("page1.html")
})
my.Get("/other", func(ctx iris.Context) {
ctx.View("page1.html")
})
}
// http://localhost:8080
// http://localhost:8080/nolayout
// http://localhost:8080/my
// http://localhost:8080/my/other
app.Run(iris.Addr(":8080"))
}
~~~
File: view/template_html_2/templates/layouts/layout.html
~~~
<html>
<head>
<title>Layout</title>
</head>
<body>
<h1>This is the global layout</h1>
<br />
<!-- 在此处渲染当前模板 -->
{{ yield }}
</body>
</html>
~~~
File: view/template_html_2/templates/layouts/mylayout.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>
~~~
File: view/template_html_2/templates/page1.html
~~~
<div style="background-color: black; color: blue">
<h1>Page 1 {{ greet "iris developer"}}</h1>
{{ render "partials/page1_partial1.html"}}
</div>
~~~
File: view/template_html_2/templates/partials/page1_partial1.html
~~~
<div style="background-color: white; color: red">
<h1>Page 1's Partial 1</h1>
</div>
~~~
- api文档
- yaag
- 认证
- 认证基本
- oauth2
- 缓存
- 客户端
- 简单的
- 配置
- 配置文件
- tml文件
- yaml文件
- 功能
- 处理程序
- Negroni Like
- http
- Real Usecase Raven
- cookies
- Basic
- 安全cookie
- 实验程序
- casbin
- 云监视
- cors
- csrf
- jwt
- 新文学
- Casbin
- 文件服务器
- Hero
- http监听
- http请求
- HTTP Responsewriter
- Miscellaneous
- MVC
- mvc概观
- 中间件
- Hello World
- 登陆
- Session 控制器
- Singleton
- MVC基本
- ORM
- xorm
- 概况
- 路由
- 概观
- 自定义上下文
- 自定义包装
- 动态路径
- 相反
- HTTP错误
- 路由状态
- 路由基本
- Sessions
- 构建
- 子域
- 重定向
- 万维网
- Single
- 通配符
- 多域名
- 测试
- 教程
- 视图
- Template Html 0
- Template Html 1
- Template Html 2
- Template Html 3
- Template Html 4
- Webassembly
- Websocket
