我正在尝试创建HTML布局局部文件,以使用前件作为数据源并使用hugo模板进行渲染,以添加不同的html元素。 例如,前件具有此属性
---
animal:
type:"bear"
---
现在部分看起来像这样:
{{ if eq .Params "animal.type" "dog" | or eq .Params "animal.type" "bear" | or eq .Params "animal.type" "fox" | or eq .Params "animal.type" "wolf" }}
<p> Belongs to the Canine family, they have distinctive fangs. <p>
{{ end }}
我运行hugo server
时引发以下错误:
在以下位置执行“ partials / canine.html”:eq的参数个数错误:希望至少有1个得到0
我对或操作员的配管是错误的吗?还是问题出在哪里?
文件夹结构如下所示:single.html正在调用animalsDetails.html
,这个正在调用canine.html
我不认为这是问题所在,但以防万一。
|layouts
|_defaults
single.html
|partials
animalDetails.html
canine.html
答案 0 :(得分:4)
您可能需要正确使用.Params
并确保使用圆括号。
尝试一下(未测试):
{{ if eq .Params.animal.type "dog" | or (eq .Params.animal.type "bear") | or (eq .Params.animal.type "fox") | or (eq .Params.animal.type "wolf") }}
<p> Belongs to the Canine family, they have distinctive fangs. <p>
{{ end }}
我建议不要在Hugo表达式中使用bar,但我遇到了问题(尽管这是replaceRE的情况)。
这是不使用横条的解决方案:
{{ if or (eq .Params.animal.type "dog") (eq .Params.animal.type "bear") (eq .Params.animal.type "fox") (eq .Params.animal.type "wolf") }}
<p> Belongs to the Canine family, they have distinctive fangs. <p>
{{ end }}
如果您需要更多帮助,请随时发表评论! ?
编辑1:修正了错字并添加了其他推荐的解决方案。
答案 1 :(得分:0)
{{ if or (eq .Params.animal.type "dog") (eq .Params.animal.type "bear") (eq .Params.animal.type "fox") (eq .Params.animal.type "wolf") }}
<p> Belongs to the Canine family, they have distinctive fangs. <p>
{{ end }}
做到了