Answers.Body: <p>You can use the Site component</p>
  
  <h3>PHP</h3>
  
  <pre><code>$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;
      }
  }
  </code></pre>
  
  <h3>Twig</h3>
  
  <pre><code>{% set groups = craft.app.getSites().getAllGroups() %}
  {% for group in groups %}
      {{ group.name }}
      {% for site in group.getSites() %}
          {{ site.name }}
      {% endfor %}
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-30T07:55:26.687Z
Answers.Text: It will return  all sites of all groups
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-30T07:56:28.203Z
Answers.Text: Ok, picking up this task again. 
  Unfortunately, it's not returning the site that belongs to the groups.
  
  This is my result on your twig code example Robin:
  Africa 
  Asia 
  Australia 
  Europe 
  North America 
  South America
Answers.UserDisplayName: John Stevens
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-23T06:51:39.170Z
Answers.LastActivityDate: 2018-06-30T12:34:59.783Z
Answers.LastEditDate: 2018-06-30T12:34:59.783Z
Answers.UserDisplayName: Robin Schambach
Body: <p>We have many country websites on different continents. In the CP we group the sites, where the group has the name of the continent.</p>
  
  <p>Now we want to group the sites in the templates in the same way.</p>
  
  <p>I have this, but it is not giving back the group.</p>
  
  <pre><code>{% 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 %}
  </code></pre>
  
  <p>Hope somebody can point me in the right direction.</p>
  
  <p>Thanks!</p>
  
Tags: <localization><filter><multi-site>
Title: Group Sites by Groups
ThreadText: # Group Sites by Groups
  
  (Asked by: username_0 on 2018-05-22)
  
  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 }} <br>
      {% for country in countriesInGroup %}
          {{country.language}} <br>
      {% endfor %}
  {% endfor %}
  
  ```
  
  Hope somebody can point me in the right direction.
  
  Thanks!
  
  **Tags:** localization, filter, multi-site
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-05-23. Score: 2 | Accepted answer
  
  You can use the Site component
  
  ### PHP
  
  ```
  $groups = Craft::$app->getSites()->getAllGroups();
  foreach ($groups as $group){
      echo $group->name;
      foreach ($group->getSites() as $site){
          echo $site->name;
      }
  }
  
  ```
  
  ### Twig
  
  ```
  {% set groups = craft.app.getSites().getAllGroups() %}
  {% for group in groups %}
      {{ group.name }}
      {% for site in group.getSites() %}
          {{ site.name }}
      {% endfor %}
  {% endfor %}
  
  ```
  
  > **Comments:**
  > **username_1**: It will return  all sites of all groups  
  > **username_0**: Ok, picking up this task again.  Unfortunately, it's not returning the site that belongs to the groups.  This is my result on your twig code example username_1: Africa  Asia  Australia  Europe  North America  South America  
  
  ---
  
  