Skip to content
This repository has been archived by the owner on Nov 30, 2024. It is now read-only.

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 %}