我的模板中有一个if else块。当else if
为真时,它会呈现为空,就好像else
或else if
不存在一样
这是我的模板
我也在使用text/template
因为html/template
将页面完全空了
//the template
<script>
{{if.PassChange}}
swal("{{.Lang.Success}}", "{{.Lang.PleaseLogin}}", "success")
{{end}}
{{if.UserExists}}
swal("{{.Lang.Fail}}", "{{.Lang.AlreadyMember}}", "error")
{{end}}
</script>
//rendering part
BasePath.Get("/", func(w http.ResponseWriter, r *http.Request) {
tpl.ExecResponse(w, struct{Lang map[string]string ; UserExists bool}{Lang:lang.GetLang(r),UserExists:true})
})
答案 0 :(得分:3)
如果从执行模板中打印错误,您会发现模板无法评估字段PassChange
。一种可能的解决方法是向结构添加PassChange字段。
tpl.ExecResponse(w, struct{PassChange bool; Lang map[string]string ; UserExists bool}{Lang:lang.GetLang(r),UserExists:true})