I have edited the default home page (/user/pages/01.home) and changed the page file into “Modular”.
Under the home page, I’ve created a new modular page called “Categories” (/user/pages/01.home/_categories).
Under the categories page, I’ve added another modular page, where each modular page has a taxonomy like “Term 1”, “Term 2”, “Term 3”, “Term 4” and so on.
I’ve created a *.html.twig to print those content.
Now, how can I find the categories used and group them based from their taxonomy terms? Also, I would like to add the category itself as a title on each group.
This is what I’ve got so far (which I found in the documentation), and I’ve wanted to find the categories dynamically instead of typing them one by one just to find and print the taxonomy associated with it.
{% for post in taxonomy.findTaxonomy({'category':['Term 1']}) %}
{{ post.title }}
{{ post.content }}
{% endfor %}
{% for post in taxonomy.findTaxonomy({'category':['Term 2']}) %}
{{ post.title }}
{{ post.content }}
{% endfor %}
{% for post in taxonomy.findTaxonomy({'category':['Term 3']}) %}
{{ post.title }}
{{ post.content }}
{% endfor %}
{% for post in taxonomy.findTaxonomy({'category':['Term 4']}) %}
{{ post.title }}
{{ post.content }}
{% endfor %}
---
Thank you for your quick response rhukster. Yep, that is what in my frontmatter. When I’ve copied and pasted the code you’ve provided, there are no content printed. The output is “null” when I tried to debug the “page.taxonomy.category”.
<div class="menu-items">
<div class="container">
{% set terms = [] %}
{% for post in page.find('/home/_03menu').children %}
{% for term in post.taxonomy.category %}
{% if term not in terms %}
{% set terms = terms|merge([term]) %}
{% endif %}
{% endfor %}
{% endfor %}
{% for term in terms %}
<div class="col-lg-3">
<h2> {{ term }} </h2>
{% for p in taxonomy.findTaxonomy({'category' : term}) %}
<div class="item row">
<h3> {{ p.header.title }} </h3>
<p> {{ p.content }} </p>
</div>
{% endfor %}
</div>
{% endfor %}
</div>
</div>
---