Skip to content

Instantly share code, notes, and snippets.

@stilliard
Created July 10, 2019 00:00
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save stilliard/57cf2d5b2a3470c347cc3953e0ae0140 to your computer and use it in GitHub Desktop.
module collection demo with tags and search
<style>
.mod-tags {}
.mod-tags .active { font-weight: bold; }
</style>
<h1>{{ module.name }} Collection</h1>
<form action="{{ module.link }}" method="get">
<fieldset>
{# When combining search with tag filters, you'll need the search form to add hidden fields for the selected tags #}
{% for k, values in filters | filter((k,v) => k!='search') %}
{% for v in values %}
<input type="hidden" name="{{ k | escape }}[]" value="{{ v | escape }}">
{% endfor %}
{% endfor %}
{# search field #}
<input type="search" name="search" value="{{ filters.search | escape }}">
<button type="submit">Search</button>
<a href="{{ module.link }}">reset</a>
</fieldset>
</form>
{# for all the tag groups setup, show a block for each with selectable tags inside #}
{% for tagGroup in module.tagGroups %}
<br>
<fieldset>
<strong>{{ tagGroup.name }}</strong>
<ul class="inline-list mod-tags">
{% for tag in tagGroup.tags %}
<li><a class="{{ tag.slug in filters[tagGroup.slug] ? 'active' : ''}}" href="{{ tag.link }}{{ filters.search ? '&search=' ~ filters.search | escape : '' }}">{{ tag.name }}</a></li>
{% endfor %}
</ul>
</fieldset>
{% endfor %}
<ul>
{# list out objects inside this module #}
{% for object in objects %}
{# to display each use the each.html.twig file in this same folder #}
{% include module.template_folder ~ 'html/each.html.twig' %}
{% else %}
<li><em>None found</em></li>
{% endfor %}
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment