I've started off with this solution: http://craftcookbook.net/recipes/330
{% set testsByAllergenGroup = {} %}
{% set entries = craft.entries.section('tests').order('title asc') %}
{% set groups = craft.categories.group('allergenGroup') %}
{% for group in groups %}
{% set entries = entries.relatedTo(group) %}
{% if entries|length %}
{% set testsByAllergenGroup = testsByAllergenGroup|merge({
(group.title): entries
}) %}
{% endif %}
{% endfor %}
{% if groups|length %}
<div class="row">
<div class="small-12 columns">
<ul class="inline-list">
<li>Allergy Groups:</li>
{% for group in groups %}
<li><a href="#{{ group.slug }}">{{ group.title }}</a></li>
{% endfor %}
</ul>
</div>
</div>
{% for groupTitle, groupTests in testsByAllergenGroup %}
<h2 id="{{ groupTitle }}" class="content__subtitle">
{{ groupTitle }}
</h2>
<div class="content__panel">
{% for entry in groupTests %}
<div class="test-menu-item">
<div class="row">
<div class="medium-7 columns">
<h4><a href="{{ entry.url }}">{{ entry.title }}</a></h4>
</div>
<div class="medium-5 columns">
<ul class="button-group radius even-2">
<li><a href="{{ entry.url }}" class="info tiny button">View Details</a></li>
<li><a href="{{ entry.url }}" class="tiny button">Add to Cart ($40)</a></li>
</ul>
</div>
</div>
</div>
{% endfor %}
</div>
<p>
<a href="#top" class="content__link--top">BACK TO TOP</a>
</p>
{% endfor %}
{% endif %}
I'm hoping to output the group title and slug, but this code will only allow for one variable to be set in the merge set:
{% set testsByAllergenGroup = testsByAllergenGroup|merge({
(group.title): entries
}) %}
I'm hoping to do something like this:
{% for group, groupTests in testsByAllergenGroup %}
<h2 id="{{ group.slug }}" class="content__subtitle">
{{ group.id }}
</h2>
Can you guys help me out? Thanks!
p.s. this is my first major Craft CMS project so Twig is new to me ;)