<p>You could use the <a href="http://buildwithcraft.com/docs/templating/filters#group" rel="nofollow"><code>group</code></a> filter to group your tags by tag groups:</p>

<pre><code>{% set entries = craft.entries.section('gallery').limit(null) %}

&lt;ul&gt;

    {# Get all the tags related to our gallery entries and group them by tag group #}
    {% set allGalleryTags = craft.tags.relatedTo(entries)|group('group') %}

    {# Loop the tag groups #}
    {% for tagGroup, tagsInGroup in allGalleryTags %}

        &lt;li&gt;
            &lt;h2&gt;{{ tagGroup }}&lt;/h2&gt;
            &lt;ul&gt;

                {# Loop the tags of this group #}
                {% for tag in tagsInGroup %}
                    &lt;li&gt;{{ tag.name }}&lt;/li&gt;
                {% endfor %}

            &lt;/ul&gt;
        &lt;/li&gt;

    {% endfor %}

&lt;/ul&gt;
</code></pre>

CC BY-SA 3.0
2014-11-19T08:38:12.107Z
Awesome. Thank you very much dude. It works flawless.
Cipick
CC BY-SA 3.0
2014-11-19T09:19:27.887Z
Glad to help, @Cipick. If you have lots of tags you could further group them by the first letter: `{% for letter, tagByLetter in tagsInGroup|group('name|slice(0, 1)') %}`.
carlcs
CC BY-SA 3.0
2014-11-18T11:34:00.907Z
2014-11-18T11:54:49.110Z
2014-11-18T11:54:49.110Z
carlcs
<p>I'm developing a masonry photo gallery with some filters (colors, style, manufacturer, etc) and I want to use tags to filter them by. I need some navigation which should look like this:</p>

<pre class="lang-html prettyprint-override"><code>&lt;ul&gt;
    &lt;li&gt;Tag Group 1
        &lt;ul&gt;
            &lt;li&gt;Tag 1&lt;/li&gt;
            &lt;li&gt;Tag 2&lt;/li&gt;
        &lt;/ul&gt;
    &lt;/li&gt;
    &lt;li&gt;Tag Group 2
        &lt;ul&gt;
            &lt;li&gt;Tag 3&lt;/li&gt;
            &lt;li&gt;tag 4&lt;/li&gt;
        &lt;/ul&gt;
    &lt;/li&gt;
&lt;/ul&gt;
</code></pre>

<p>I read this article <a href="https://craftcms.com/support/active-tags" rel="nofollow noreferrer">https://craftcms.com/support/active-tags</a> but I can't figure out how to get all group tags and for them all the tags that are actualy in use. I think i should use </p>

<pre><code>{% for tag in craft.tags.group('blogTags') %}
</code></pre>

<p>but I want to get all the group handles in a loop dynamically.</p>

<templating><navigation><tags><group>
How do I list the tag groups that are actually in use?
# How do I list the tag groups that are actually in use?

(Asked by: username_0 on 2014-11-18)

I'm developing a masonry photo gallery with some filters (colors, style, manufacturer, etc) and I want to use tags to filter them by. I need some navigation which should look like this:

    Tag Group 1
        
            Tag 1
            Tag 2
        
    
    Tag Group 2
        
            Tag 3
            tag 4
        
    


I read this article https://craftcms.com/support/active-tags but I can't figure out how to get all group tags and for them all the tags that are actualy in use. I think i should use 
{% for tag in craft.tags.group('blogTags') %}

but I want to get all the group handles in a loop dynamically.

**Tags:** templating, navigation, tags, group

---

## 1 answers

### Answer by username_1 on 2014-11-18. Score: 4 | Accepted answer

You could use the group filter to group your tags by tag groups:
{% set entries = craft.entries.section('gallery').limit(null) %}



    {# Get all the tags related to our gallery entries and group them by tag group #}
    {% set allGalleryTags = craft.tags.relatedTo(entries)|group('group') %}

    {# Loop the tag groups #}
    {% for tagGroup, tagsInGroup in allGalleryTags %}

        
            {{ tagGroup }}
            

                {# Loop the tags of this group #}
                {% for tag in tagsInGroup %}
                    {{ tag.name }}
                {% endfor %}

            
        

    {% endfor %}

> **Comments:**
> **username_0**: Awesome. Thank you very much dude. It works flawless.  
> **username_1**: Glad to help, @Cipick. If you have lots of tags you could further group them by the first letter: `{% for letter, tagByLetter in tagsInGroup|group('name|slice(0, 1)') %}`.  

---

