[英]How do I chain if statements in Jekyll?
I am using a logic operator in Jekyll but it's not working.我在 Jekyll 中使用逻辑运算符,但它不起作用。
Page one, two and three all use the same layout (part of a multilingual solution, works good but requires logical loops for some layout control to keep things DRY.)第一页、第二页和第三页都使用相同的布局(多语言解决方案的一部分,效果很好,但需要一些布局控制的逻辑循环以保持干燥。)
Here's the code:这是代码:
{% if page.type == "post" %}
{% include post.html %}
{% elseif page.class == "contact" %}
{% include contact.html %}
{% else %}
{{ content }}
{% endif %}
If I break it down to just an else
and an if else
setup, with any two of the tree, everything works.如果我将它分解为一个
else
和一个if else
设置,使用任意两个树,一切正常。 But as soon as I use a third condition it breaks.但是一旦我使用第三个条件,它就会中断。 Am I limited to two conditionals with Jekyll?
Jekyll 是否仅限于两个条件? I can potentially restructure to make a
case
operator applicable, but I'd prefer to understand the fundamental problem here.我可能会重组以使
case
运算符适用,但我更愿意理解这里的基本问题。 Thanks all.谢谢大家。
In Jekyll/Liquid else-if is spelt elsif
, ie:在 Jekyll/Liquid 中 else-if 拼写为
elsif
,即:
{% if page.type == "post" %}
{% include post.html %}
{% elsif page.class == "contact" %}
{% include contact.html %}
{% else %}
{{ content }}
{% endif %}
You can either use else if
or elsif
.您可以使用
else if
或elsif
。 elseif
is wrong and will throw an error. elseif
是错误的,会抛出错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.