Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new JB/file_exists helper. #245

Merged
merged 1 commit into from
Mar 15, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions _includes/JB/file_exists
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{% comment %}<!--
param: file = "/example/file.png"
return: file_exists_result = true

examples:
{% include JB/file_exists file="/404.html" %}
{% if file_exists_result %}Found "/404.html"!{% else %}Did not find "/404.html".{% endif %}

{% assign filename = "/405.html" %}
{% include JB/file_exists file=filename %}
{% if file_exists_result %}Found "{{ filename }}"!{% else %}Did not find "{{ filename }}".{% endif %}

NOTE: the BREAK statement in the FOR loop assumes Liquid >= 2.5.0

-->{% endcomment %}

{% assign file_exists_result = false %}

{% if include.file %}
{% for static_file in site.static_files %}
{% if static_file.path == include.file %}
{% assign file_exists_result = true %}
{% break %}
{% endif %}
{% endfor %}
{% endif %}