所以我正在做一个简单的 if 检查结构中的布尔值,但它似乎不起作用,它只是停止渲染 HTML。
所以下面的结构是这样的:
type Category struct {
ImageURL string
Title string
Description string
isOrientRight bool
}
现在我有一个 Category 结构的切片,我可以用一个范围来显示它。
Bellow 是一个结构的示例:
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}}