【问题标题】:Include Jekyll template ONLY if it exists仅包含 Jekyll 模板(如果存在)
【发布时间】:2016-03-13 05:31:55
【问题描述】:

另一个问题中有this answer,但它不符合我的需求。

我需要include_includes 中的模板当且仅当它存在时。

【问题讨论】:

标签: ruby jekyll


【解决方案1】:

This 可能会派上用场。

基本思想是将 include 块放在 capture 块中,以便将其内容保存到变量中。

如果模板不存在,变量将包含错误消息而不是模板内容,否则最好包含实际模板。

{% capture the_snippet_content %}{% include the_snippet %}{% endcapture %}
{% unless the_snippet_content contains "Liquid error" %}
    {{the_snippet}}
{% endunless %}

【讨论】:

  • 当我尝试使用它时,Liquid 错误导致项目无法构建,捕获似乎没有捕获异常。
猜你喜欢
  • 2014-05-14
  • 1970-01-01
  • 2015-11-13
  • 2013-01-07
  • 1970-01-01
  • 2015-05-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多