Group Sites by Groups We have many country websites on different continents. In the CP we group the sites, where the group has the name of the continent.

Now we want to group the sites in the templates in the same way.

I have this, but it is not giving back the group.

{% set allSites = craft.app.sites.getAllSites() %}
{% set allGroups = allSites|group('allSites.group') %}

{% for group, countriesInGroup in allGroups %}
    {{ group }} &lt;br&gt;
    {% for country in countriesInGroup %}
        {{country.language}} &lt;br&gt;
    {% endfor %}
{% endfor %}


Hope somebody can point me in the right direction.

Thanks!
You can use the Site component

PHP

$groups = Craft::$app-&gt;getSites()-&gt;getAllGroups();
foreach ($groups as $group){
    echo $group-&gt;name;
    foreach ($group-&gt;getSites() as $site){
        echo $site-&gt;name;
    }
}


Twig

{% set groups = craft.app.getSites().getAllGroups() %}
{% for group in groups %}
    {{ group.name }}
    {% for site in group.getSites() %}
        {{ site.name }}
    {% endfor %}
{% endfor %}