【发布时间】:2016-03-13 05:31:55
【问题描述】:
另一个问题中有this answer,但它不符合我的需求。
我需要include_includes 中的模板当且仅当它存在时。
【问题讨论】:
另一个问题中有this answer,但它不符合我的需求。
我需要include_includes 中的模板当且仅当它存在时。
【问题讨论】:
This 可能会派上用场。
基本思想是将 include 块放在 capture 块中,以便将其内容保存到变量中。
如果模板不存在,变量将包含错误消息而不是模板内容,否则最好包含实际模板。
{% capture the_snippet_content %}{% include the_snippet %}{% endcapture %}
{% unless the_snippet_content contains "Liquid error" %}
{{the_snippet}}
{% endunless %}
【讨论】: