search.twig 1.5 KB

1234567891011121314151617181920212223242526272829303132
  1. {% extends "index.twig" %}
  2. {% set sstring = url_param('q','string' ) %}
  3. {% set titlesonly = url_param('titlesonly','boolean' ) %}
  4. {% set advice = '<h4>Please do not use an empty search string.<br />Use the <span class="desktop-device">sidebar</span><span class="mobile-device">top menu</span> search box to enter a query, or try some tags!</h4>' %}
  5. {% block content %}
  6. <article>{% if not sstring %}{{ advice|raw }}
  7. {% else %}
  8. <blockquote><p>{{ search_tooltip }}</p></blockquote>
  9. {# it would be nice if the search weren't repeated for each page... #}
  10. {% set sstring = sstring|lower %}
  11. {% set paging_array = {} %}
  12. {% if titlesonly == 'true' %}
  13. {% for page in tbpages %}
  14. {% if sstring in page.title|striptags|lower %}
  15. {% set paging_array = paging_array|merge([page]) %}
  16. {% endif %}
  17. {% endfor %}
  18. {% else %}
  19. {% for page in tbpages %}
  20. {% if sstring in page.id|content|striptags|lower or sstring in page.title|striptags|lower or sstring in page.id|lower %}
  21. {% set paging_array = paging_array|merge([page]) %}
  22. {% endif %}
  23. {% endfor %}
  24. {% endif %}
  25. {% set count = paging_array|length %}
  26. <h4>{{ count }} search results for "{{sstring}}"
  27. {% if count == 0 %}<br />{{ advice|raw }}{% endif %}</h4>
  28. {% set paging_url_base = current_page.url ~ '?q=' ~ sstring ~ '&' %}
  29. {% include 'includes/paging.twig' %}
  30. {% endif %}</article>
  31. {% endblock content %}