2016-11-23 115 views
0

我有一个_includes文件夹,其中我有nav子文件夹包含一个nav.html文件。使用Jekyll如何检查文件夹中是否存在文件?

我一直在试图检查nav中是否存在nav.html。如果是这样,我想包含该文件。如果它不存在,我的模板将会有一个默认的nav

这是我现在所拥有的代码:

{% for static_file in site.static_files %} 
    {% if static_file.path == '/nav.html' %} 
     {% include nav.html %} 
    {% endif %} 
{% endfor %} 

希望你们能帮助我。

提前

回答

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

相关问题