我有一个_includes
文件夹,其中包含nav
文件的nav.html
子文件夹。
我一直试图检查nav.html
中是否存在nav
。如果是,我想要包含nav.html
文件。如果它不存在,我的模板将有一个默认的nav
。
这是我现在的代码:
{% for static_file in site.static_files %}
{% if static_file.path == '/nav.html' %}
{% include nav.html %}
{% endif %}
{% endfor %}
希望你们能帮助我。
非常感谢提前
答案 0 :(得分:0)
我无法使用现有的液体标签找到解决方案,所以我通过使用带有自定义液体标签的插件解决了这个问题。
{% capture fileExists %}{% file_exists _includes/nav/custom/nav.html %}{% endcapture %}
{% if fileExists=="true" %}
{% include /nav/custom/nav.html %}
{% else %}
{% include /nav/default/nav.html %}
{% endif %}
请参阅GitHub Repo