file_exists 787 B

1234567891011121314151617181920212223242526
  1. {% comment %}<!--
  2. param: file = "/example/file.png"
  3. return: file_exists_result = true
  4. examples:
  5. {% include JB/file_exists file="/404.html" %}
  6. {% if file_exists_result %}Found "/404.html"!{% else %}Did not find "/404.html".{% endif %}
  7. {% assign filename = "/405.html" %}
  8. {% include JB/file_exists file=filename %}
  9. {% if file_exists_result %}Found "{{ filename }}"!{% else %}Did not find "{{ filename }}".{% endif %}
  10. NOTE: the BREAK statement in the FOR loop assumes Liquid >= 2.5.0
  11. -->{% endcomment %}
  12. {% assign file_exists_result = false %}
  13. {% if include.file %}
  14. {% for static_file in site.static_files %}
  15. {% if static_file.path == include.file %}
  16. {% assign file_exists_result = true %}
  17. {% break %}
  18. {% endif %}
  19. {% endfor %}
  20. {% endif %}