Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Taxonomy list in drop-down

Started by Muut Archive 10 years ago · 3 replies · 613 views
10 years ago

Excuse me if I am using this wrong. But I have a church website I am building which has sermon categories that will be defined by whoever the author is that creates the post (blog page).

I have search setup but also want to provide drop-downs to sort by pastor and series. The code below will grab all of the sermon series values, but many of these have identical values.

TWIG
<select>
   {% for i in page.children %}
      {% for series in i.taxonomy.series %}
      <option>{{series}}</option>
      {% endfor %}
   {% endfor %}
</select>

If not obvious, I would like each sermon only to display once, and then have that selection take you to a results page with all sermons under that value (similar to how clicking a taxonomy tag will sort results to that tag). Am I overcomplicating this or is there a solution that I have overlooked?

BTW, I have looked at the taxonomy list plugin and a tag cloud is not a feasible solution due to the amount of information.

10 years ago

That was it!

Here is the code in case anyone else runs into this.

TWIG
{% set allseries = [] %}
{% for i in page.children %}
  {% for series in i.taxonomy.series %}
    {% if series not in allseries %}
    {% set allseries = allseries|merge([series]) %}
    {% endif %}
  {% endfor %}
{% endfor %}
<select>
  {% for i in allseries %}
    <option>{{i}}</option>
  {% endfor %}
</select>

If anyone knows a better way, please share!

👍 1
10 years ago

Alternatively you can perform this logic in the PHP of the plugin and set the resulting array to variable that your twig can simply loop over.

Either way works though :)

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1368 9 years ago
Archive · by Muut Archive, 9 years ago
2 940 9 years ago
Archive · by Muut Archive, 9 years ago
2 4069 9 years ago
Archive · by Muut Archive, 9 years ago
1 2960 9 years ago
Archive · by Muut Archive, 9 years ago
3 1125 9 years ago