【问题标题】:Multiple OR options in Jekyll include (liquid template)Jekyll 中的多个 OR 选项包括(液体模板)
【发布时间】:2018-02-01 00:53:49
【问题描述】:

我创建了一个 image 包含很多类似于 Jekyll documentation 中的那个。

如果提供了alt 变量,我将根据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 块?

【问题讨论】:

    标签: html include jekyll liquid


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 2013-01-07
      • 2016-06-05
      • 2023-03-11
      • 2012-03-02
      • 2018-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多