GolangNote

Golang笔记

go 模版,在循环里引用外部变量

Permalink

go 模版里的循环,在循环里引用外部变量时要在前面加个美元符$,如下

HTML: 循环里引用外部变量
1
2
3
4
5
6
<label for="state">类型</label>
<select id="state" class="pure-input-1-2" name="type">
    {{range $_, $v := .Types}}
    <option value="{{$v}}" {{if eq $v $.CurrentType}}selected="selected"{{end}}>{{$v}}</option>
    {{end}}
</select>

本文网址: https://golangnote.com/topic/93.html 转摘请注明来源

Related articles

Golang quicktemplate 模版快速入门

Golang 有很多的模版引擎,自带的 `html/template` 也很好,大多数情况都能满足需求,只是有些逻辑、条件判断不好在模版里实现, `quicktemplate` 是个很好的选择。...

Write a Comment to "go 模版,在循环里引用外部变量"

Submit Comment Login
Based on Golang + fastHTTP + sdb | go1.20 Processed in 0ms