我正在尝试创建go html(Go 1.13)with a context {{。}}。
我设法将上下文变量显示为div值,但是我找不到在HTML属性中放入上下文变量的正确方法。
例如,此代码有效:
{{ if .AppCtx.Title }}
<a href="/">{{ .AppCtx.Title }}</a>
{{end}}
但这似乎不起作用:
<a href="{{ if .AppCtx.Link }}{{.AppCtx.Link}} {{end}}">
我尝试了不同的语法:
- 单引号:
<a href='{{ if .AppCtx.Link }}{{.AppCtx.Link}} {{end}}'>
- 条件语句前面的双引号:
<a href=""{{ if .AppCtx.Link }}{{.AppCtx.Link}} {{end}}>
- 双引号:
<a href="{{ if .AppCtx.Link }}{{.AppCtx.Link}} {{end}}">
我已经读过https://golang.org/pkg/html/template/,但没有发现任何线索。