我正在尝试创建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/,但是没有发现任何线索。
您是要这样做吗?
<a href="{{ if .AppCtx.Title}}{{.AppCtx.Title}} {{end}}">