Go 笔记(学习iris)

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

评论规范写法

go
       
// 方法名 说明

// Example 示例
func Example() {

}
1234567

iris 模板语法

公共模版

使用 yield 输出内容

html
  
{{ yield }}
12

传其他部位的内容

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

html
  
{{ part "header" }}
12

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

文件 blog/index.html

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

根据路由名生成链接

go
   

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

使用

 
{{ urlpath "home" }}
1

生成链接自动加上域名

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

使用

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