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

Multiple OR options in Jekyll include (liquid template)

我创建了一个 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 块?

我误解了发生的事情。我将竖线阅读为 OR(ruby 风格)而不是管道(unix 风格)。在 Liquid 中,管道用作 filters.

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

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