问题
I have an _includes
folder, and within it I have nav
subfolder containing a nav.html
file.
I've been trying to check if nav.html
exists in nav
. If it does, I want to include that nav.html
file. If it doesnt exist, there will be a default nav
for my template.
Here's the code I have right now:
{% for static_file in site.static_files %}
{% if static_file.path == '/nav.html' %}
{% include nav.html %}
{% endif %}
{% endfor %}
Hope you guys can help me out.
Many thanks in advance
回答1:
I am not able to find the solution using existing liquid tags so I solved this by using a plugin with a custom liquid tag.
{% 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 %}
See GitHub Repo
来源:https://stackoverflow.com/questions/40755367/using-jekyll-how-can-i-check-if-file-exist-in-my-folder