Go 笔记(学习iris)

Fork Me On Github
zodream 编程技术 Go 2019年06月

评论规范写法

// 方法名 说明

// Example 示例
func Example() {

}

iris 模板语法

公共模版

使用 yield 输出内容

{{ yield }}

传其他部位的内容

先在公共模版声明 此处使用 header 的内容

{{ part "header" }}

再在页面中定义 命名规则 相对于模板根目录的相对路径 -header

文件 blog/index.html

{{ define "blog/index-header"}}
<link type="text/css" href="/assets/css/blog.css" rel="stylesheet" media="all">
{{ end }}

根据路由名生成链接


homeRoute := app.Get("/", controllers.Index)
homeRoute.Name = "home"

使用

{{ urlpath "home" }}

生成链接自动加上域名

rv := router.NewRoutePathReverser(app, router.WithHost("zodream.cn:443"))
tmpl.AddFunc("url", rv.URL)

使用

{{ url "home" }}
点击查看全文
0 721 0