gin-HTML模板渲染
This commit is contained in:
@@ -1,9 +0,0 @@
|
||||
{{ define "about" }}
|
||||
{{ template "base" . }}
|
||||
|
||||
{{ block "title" . }}关于我们{{ end }}
|
||||
{{ block "content" . }}
|
||||
<h2>关于我们</h2>
|
||||
<p>这里可以写团队介绍、网站背景或使命。</p>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
@@ -1,13 +0,0 @@
|
||||
{{ define "articles" }}
|
||||
{{ template "base" . }}
|
||||
|
||||
{{ block "title" . }}文章列表{{ end }}
|
||||
{{ block "content" . }}
|
||||
<h2>文章列表</h2>
|
||||
<ul>
|
||||
{{ range .Articles }}
|
||||
<li>{{ .Title }} - {{ .Date }}</li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
@@ -1,14 +0,0 @@
|
||||
{{ define "contact" }}
|
||||
{{ template "base" . }}
|
||||
|
||||
{{ block "title" . }}联系我们{{ end }}
|
||||
{{ block "content" . }}
|
||||
<h2>联系我们</h2>
|
||||
<form>
|
||||
<label>姓名:</label><input type="text" name="name"><br>
|
||||
<label>邮箱:</label><input type="email" name="email"><br>
|
||||
<label>留言:</label><textarea name="message"></textarea><br>
|
||||
<button type="submit">提交</button>
|
||||
</form>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
@@ -1,9 +1,56 @@
|
||||
{{ define "index" }}
|
||||
{{ template "base" . }}
|
||||
{{define "pages/index.html"}}
|
||||
<!doctype html>
|
||||
<html lang="zh">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>{{.title}}</title>
|
||||
</head>
|
||||
<body>
|
||||
{{/*输出*/}}
|
||||
<h2>{{.title}}</h2>
|
||||
|
||||
{{ block "title" . }}首页{{ end }}
|
||||
{{ block "content" . }}
|
||||
<h1>欢迎来到我的 Gin 网站</h1>
|
||||
<p>这里是首页内容,可以展示最新文章或公告。</p>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{/*定义变量*/}}
|
||||
{{$t :=.title}}
|
||||
<h4>{{$t}}</h4>
|
||||
|
||||
|
||||
{{/*条件判断*/}}
|
||||
{{if ge .score 60}}
|
||||
<p>及格</p>
|
||||
{{else}}
|
||||
<P></P>
|
||||
{{end}}
|
||||
|
||||
{{/*循环遍历数据*/}}
|
||||
|
||||
{{range $key,$value:=.hobby}}
|
||||
<ul>
|
||||
<li>{{$key}}--{{$value}}</li>
|
||||
</ul>
|
||||
{{end}}
|
||||
|
||||
{{range $key,$value:=.newsList}}
|
||||
<ul>
|
||||
<li>{{$key}}--{{$value.Title}}--{{$value.Content}}</li>
|
||||
</ul>
|
||||
{{end}}
|
||||
|
||||
{{range $key,$value:=.newsList2}}
|
||||
<ul>
|
||||
<li>{{$key}}--{{$value.Title}}--{{$value.Content}}</li>
|
||||
</ul>
|
||||
{{else}}
|
||||
<li>没有数据</li>
|
||||
{{end}}
|
||||
|
||||
{{/*结构结构*/}}
|
||||
{{with .news}}
|
||||
{{.Title}}
|
||||
{{.Content}}
|
||||
{{end}}
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
{{end}}
|
||||
Reference in New Issue
Block a user