{% set tagCloud = widget_service.findTagCloud() %} {% if tagCloud|length > 0 %}

Tags

{# Detection du regroupement : si au moins un tag a une famille, on regroupe ; sinon on garde le rendu plat historique pour ne pas casser la sidebar blog. #} {% set hasGroups = false %} {% for row in tagCloud %} {% if row[0].tagGroup %}{% set hasGroups = true %}{% endif %} {% endfor %} {% if hasGroups %} {# Construction des buckets : "Sans famille" puis chaque famille presente #} {% set ungrouped = [] %} {% set groups = {} %} {% for row in tagCloud %} {% if row[0].tagGroup %} {% set gid = row[0].tagGroup.id %} {% set bucket = groups[gid]|default({group: row[0].tagGroup, rows: []}) %} {% set bucket = bucket|merge({rows: bucket.rows|merge([row])}) %} {% set groups = groups|merge({(gid): bucket}) %} {% else %} {% set ungrouped = ungrouped|merge([row]) %} {% endif %} {% endfor %} {% if ungrouped|length > 0 %}
{% for row in ungrouped %} {{ row[0].name }} {% if row.articleCount > 0 %} {{ row.articleCount }} {% endif %} {% endfor %}
{% endif %} {% for bucket in groups %}
{{ bucket.group.name }}
{% endfor %} {% else %} {# Rendu plat historique #}
{% for row in tagCloud %} {{ row[0].name }} {% if row.articleCount > 0 %} {{ row.articleCount }} {% endif %} {% endfor %}
{% endif %}
{% endif %}