【发布时间】:2016-11-08 19:21:02
【问题描述】:
所以我正在对结构中的布尔值进行简单的 if 检查,但它似乎不起作用,它只是停止呈现 HTML。
所以下面的结构是这样的:
type Category struct {
ImageURL string
Title string
Description string
isOrientRight bool
}
现在我有了一个 Category 结构的切片,我可以用一个范围来显示它。
下面是一个结构的示例:
juiceCategory := Category{
ImageURL: "lemon.png",
Title: "Juices and Mixes",
Description: `Explore our wide assortment of juices and mixes expected by
today's lemonade stand clientelle. Now featuring a full line of
organic juices that are guaranteed to be obtained from trees that
have never been treated with pesticides or artificial
fertilizers.`,
isOrientRight: true,
}
我尝试了多种方法,如下所示,但都没有奏效:
{{range .Categories}}
{{if .isOrientRight}}
Hello
{{end}}
{{if eq .isOrientRight true}}
Hello
{{end}}
<!-- Print nothing -->
{{ printf .isOrientRight }}
{{end}}
【问题讨论】:
标签: go struct go-templates go-html-template