2016-11-23 118 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

相關問題