-
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.
Merge pull request #245 from groundh0g/feature-fileexists
Stand-alone addition to utility functions. Low risk. Merging.
- Loading branch information
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 %} |