惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cloudbric
Cloudbric
E
Exploit-DB.com RSS Feed
SecWiki News
SecWiki News
Forbes - Security
Forbes - Security
N
News | PayPal Newsroom
S
Security @ Cisco Blogs
Schneier on Security
Schneier on Security
V
V2EX - 技术
S
Secure Thoughts
W
WeLiveSecurity
Google DeepMind News
Google DeepMind News
C
CERT Recently Published Vulnerability Notes
NISL@THU
NISL@THU
S
Securelist
S
Security Archives - TechRepublic
Know Your Adversary
Know Your Adversary
V
Vulnerabilities – Threatpost
Security Latest
Security Latest
Recent Commits to openclaw:main
Recent Commits to openclaw:main
G
GRAHAM CLULEY
H
Hacker News: Front Page
Microsoft Azure Blog
Microsoft Azure Blog
I
Intezer
Google Online Security Blog
Google Online Security Blog
美团技术团队
阮一峰的网络日志
阮一峰的网络日志
T
The Exploit Database - CXSecurity.com
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Webroot Blog
Webroot Blog
Jina AI
Jina AI
Engineering at Meta
Engineering at Meta
P
Proofpoint News Feed
The Cloudflare Blog
I
InfoQ
L
LangChain Blog
U
Unit 42
P
Proofpoint News Feed
S
Schneier on Security
S
Security Affairs
Y
Y Combinator Blog
T
Tenable Blog
N
News and Events Feed by Topic
MyScale Blog
MyScale Blog
量子位
Google DeepMind News
Google DeepMind News
Cyberwarzone
Cyberwarzone
博客园 - 聂微东
D
Darknet – Hacking Tools, Hacker News & Cyber Security
GbyAI
GbyAI
AWS News Blog
AWS News Blog

Gin on 轻风云

暂无文章

gin渲染多层目录下模板
2021-06-18 · via Gin on 轻风云

试着学习一下go的gin框架,相比php来说,坑太多了

在模板里面如果 不定义define 则相同文件名会被 覆盖 ,必须定义

项目结构:
img

layout/header.html文件
(1)任何文件要以{{define “layout/header"}} 开始,最后{{end}}结束
(2)公共头部 define

1
2
3
{{define "layout/header"}}
header
{{end}}

admin/index.html
(1)文件要以{{define “admin/index.html"}} 开始,最后{{end}}结束,这里的index可以加文件后缀,index.html
(2)需要通过{{template “layout/header" .}} 最后面有个【点】,它的意思是要把当前页面的变量传递到head.html中

1
2
3
4
{{define "admin/index.html"}}
{{template "layout/header" .}}
admin
{{end}}

输出模板代码

1
c.HTML(http.StatusOK, "admin/index.html", gin.H{})

模板渲染设置

1
r.LoadHTMLGlob("views/**/*")