Jekyll中的多个OR选项包括(液体模板)

时间:2017-08-23 12:22:47

标签: html include jekyll liquid

我创建的image包含的内容很像Jekyll documentation中的内容。

我根据提供的alt变量设置alt标记,否则设置默认值以试图让自己羞于提供一个:

alt="{{ include.alt | default: "Whoops! alt tag not provided. Please let me know via the contact page"}}"

我还有一个可选标题,这可能是alt标记的合理替代方案(请原谅)(如果caption已设置但alt未设置)。

我尝试了{{ include.alt | include.caption | default: "Whoops! alt tag not ..."}},但当alt为空且设置了字幕时,它仍然使用默认值。

是否有一种优雅的方法可以做到这一点,还是需要使用多个if / unless块?

1 个答案:

答案 0 :(得分:3)

我误解了发生的事情。我正在读垂直条作为OR(红宝石样式)而不是管道(unix样式)。在Liquid中,管道用作filters

解决方案是使用默认过滤器两次:

{{ include.alt | default: include.caption | default: "Whoops! alt tag not ..." }}

相关问题