模板语法 if 与 with 的区别
if关键字
语法如下
{{if pipeline}} T1 {{end}}
{{if pipeline}} T1 {{else}} T0 {{end}}
{{if pipeline}} T1 {{else if pipeline}} T0 {{end}}
其 pipeline 为判断条件,直接结果与我们 go 语言中所学的 if 相似
with关键字
语法如下
{{ with pipeline }} T1 {{ end }}
{{ with pipeline }} T1 {{ else }} T0 {{ end }}
其 pipeline 为判断条件,与if关键字相似,但目前我了解到的一点不同就是若 pipeline 为空则不产生输出,否则将 . 设为 pipeline 的值并执行 T1。不修改外面的 . ,否则执行T0,注意不修改 . 。
本作品采用《CC 协议》,转载必须注明作者和本文链接
推荐文章: