-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new JB/file_exists helper. Useful for things like using a large…
…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.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %} |