有 this answer在另一个问题中,但它不符合我的需求。
我需要在 _includes
中包含
一个模板 当且仅当它存在时。
最佳答案
This可能会派上用场。
基本思想是将 include block 放在 capture block 中,以便将其内容保存到变量中。
如果模板不存在,变量将包含一条错误消息而不是模板内容,否则您最好包含实际模板。
{% capture the_snippet_content %}{% include the_snippet %}{% endcapture %}
{% unless the_snippet_content contains "Liquid error" %}
{{the_snippet}}
{% endunless %}
关于ruby - 仅在存在时包含 Jekyll 模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34153472/