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

Mat*_*hew 2 html include liquid jekyll

我创建了image一个很像Jekyll 文档中的包含

如果提供,我将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 块?

Mat*_*hew 6

我误解了正在发生的事情。我将垂直条读作 OR(红宝石风格)而不是管道(unix 风格)。在 Liquid 中,管道用作过滤器

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

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