Ruby-on-rails 如何在 Jekyll 中链接 if 语句?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12423658/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I chain if statements in Jekyll?
提问by motleydev
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 elseand an if elsesetup, with any two of the tree, everything works. But as soon as I use a third condition it breaks. Am I limited to two conditionals with Jekyll? I can potentially restructure to make a caseoperator applicable, but I'd prefer to understand the fundamental problem here. Thanks all.
如果我将它分解为一个else和一个if else设置,使用任意两个树,一切正常。但是一旦我使用第三个条件,它就会中断。Jekyll 是否仅限于两个条件语句?我可能会重组以使case运算符适用,但我更愿意了解这里的基本问题。谢谢大家。
回答by huon
In Jekyll/Liquid else-if is spelt elsif, i.e.:
在 Jekyll/Liquid 中 else-if 拼写为elsif,即:
{% if page.type == "post" %}
{% include post.html %}
{% elsif page.class == "contact" %}
{% include contact.html %}
{% else %}
{{ content }}
{% endif %}

