search.twig 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. {% extends "index.twig" %}
  2. {% set sstring = url_param('q','string' ) %}
  3. {% block content %}
  4. <div>
  5. <blockquote class="small">The search function is primitive. It only searches for the literal string as entered. A search like <span>» fluffy cloud</span> will search only the exact string <span>» "fluffy cloud"</span>, and not <span>fluffy</span> AND/OR <span>cloud</span>, like search engines do.<br>Searches are case insensitive. Tags and some special characters are stripped.</blockquote>
  6. </div>
  7. {% set p = url_param('p','int',1) %}
  8. {# it would be nice if the search weren't repeated for each page, but this doesn't work: #}
  9. {# {% if p == 1 %} #}
  10. {% set sstring = sstring|lower %}
  11. {% set results = {} %}
  12. {% for page in tbpages %}
  13. {% if sstring in page.id|content|striptags|lower or sstring in page.title|striptags|lower or sstring in page.id|lower %}
  14. {% set results = results|merge([page]) %}
  15. {% endif %}
  16. {% endfor %}
  17. {% set count = results|length %}
  18. {# {% endif %} #}
  19. <h4>{{ count }} search results for "{{sstring}}"</h4>
  20. {% if config.tagblog.paging > 0 and count > config.tagblog.paging %}
  21. {% set offset = (p - 1) * config.tagblog.paging %}
  22. {% set lastpage = count//config.tagblog.paging %}
  23. {% if count%config.tagblog.paging > 0 %}{% set lastpage = lastpage + 1 %}{% endif %}
  24. {% for page in results|slice(offset,config.tagblog.paging) %}
  25. {% include 'includes/postlistitem.twig' %}
  26. {% endfor %}
  27. <div class="pagination clearfix">
  28. {% if offset >= config.tagblog.paging %}
  29. <div class="previous"><a href="/search?q={{sstring}}&p={{ p - 1 }}">&lt;Previous Page</a></div>
  30. {% endif %}
  31. {# {% if offset >= config.tagblog.paging and offset + config.tagblog.paging < length %} | {% endif %} #}
  32. <div class="current">- {{ p }}/{{ lastpage }} -</div>
  33. {% if offset + config.tagblog.paging < count %}
  34. <div class="next"><a href="/search?q={{sstring}}&p={{ p + 1 }}">Next Page&gt;</a></div>
  35. {% endif %}
  36. </div>
  37. {% else %}
  38. {% for page in results %}
  39. {% include 'includes/postlistitem.twig' %}
  40. {% endfor %}
  41. {% endif %}
  42. {% endblock content %}