Golang建站(1)

photoShare 建站问题记录

0301

第一是前端选择.之前是用的bootstrap开发.view部分还是靠自己一点一点的写.然后选择了AdminLTE模板快速开发.至于后台则是beego.至于其他的有各类的js插件,就不一一列出了.

然后关于golang 模板嵌套传值问题.首先template的渲染传值是针对主模板的.比如主模板是b.html.其中有引用了head.html,foot.html.

1
2
3
4
5
6
7
8
9
10
11
12
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
{{template "head.html"}}
<body>
{{.user.userName}}
</body>
{{template "foot.html"}}
</html>

比如上面这种写法.如果现在head.html中使用user的值必须在引用模板的末尾添加传递的值.如下:

1
{{template "head.html" .}}

这就是直接传递上下文(就是后面的那个点).调用方法就是和主模板一样:

1
{{.user.userName}}

如果是指定传递,比如:

1
{{template "head.html" .user}}

这则是只传递user.这时候相当于子模板的上下文就是user的域.调用类似,稍加修改:

1
{{.userName}}

(注意区别是少了user这个域)

客官扫码领红包哟~