Skip to content

Commit

Permalink
Added new JB/file_exists helper. Useful for things like using a large…
Browse files Browse the repository at this point in the history
…r image if available and conditionally including files. (e.g. "avatar_64x64.png" vs "avatar_256x256.png")
  • Loading branch information
groundh0g committed Feb 28, 2015
1 parent c77431d commit cdae108
Showing 1 changed file with 26 additions and 0 deletions.
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 %}

0 comments on commit cdae108

Please sign in to comment.