Answers.Body: <p>In your example, you're attempting to use a <code>SectionModel</code> instance as the key for your grouped entries. This is not possible.</p>
  
  <p>What actually happens behind the scenes is the <code>group</code> filter generates an object where the keys are the string value of the <code>SectionModel</code> instance [1], and the values are the <code>EntryModels</code> associated with that section.</p>
  
  <p>There are a few ways of achieving your desired outcome. Here's one possibility (not tested):</p>
  
  <pre><code>{% set sections = craft.sections.getAllSections() %}
  {% set entries = craft.entries.section(['first', 'second', 'third']) %}
  {% set grouped = entries|group('section') %}
  
  {% for sectionHandle, sectionEntries in grouped %}
      {% set groupSection = false %}
      {% for section in sections %}
          {% if section.name == sectionHandle %}
              {% set groupSection = section %}
          {% endif %}
      {% endfor %}
  
      {% if groupSection %}
          &lt;h1&gt;{{ groupSection.name }} - {{ groupSection.handle }}&lt;/h1&gt;
      {% endif %}
  {% endfor %}
  </code></pre>
  
  <hr>
  
  <p>[1]: The <a href="https://craftcms.com/classreference/models/SectionModel#__toString-detail" rel="nofollow noreferrer"><code>SectionModel::__toString</code> method</a> returns the <code>name</code> attribute.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-02-23T21:51:59.147Z
Answers.Text: Glad I could help 
Answers.UserDisplayName: Stephen Lewis
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-07T00:07:18.287Z
Answers.Text: Now that I have the sections outputting, I need to sort them.  Ideally by structureId.  I've tried applying supersort to the "grouped" query but I'm not getting the results I would expect.  Any advice?
Answers.UserDisplayName: triplethreat23
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-07T01:56:11.210Z
Answers.Text: You should probably post a separate question for that.
Answers.UserDisplayName: Stephen Lewis
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-02-21T00:07:21.950Z
Answers.LastActivityDate: 2017-02-21T00:07:21.950Z
Answers.UserDisplayName: Stephen Lewis
Body: <p>I have a landing page on my site where I want to list a group of sections that have entries. I also need to access the section handle of that same group of sections.</p>
  
  <p>I am having problems getting the section handle for the sections.</p>
  
  <p>Currently I get an error back that says impossible to access attribute ("handle") on a string variable.</p>
  
  <pre><code>        {% set specialEntries = craft.entries.section(['sec1','sec2','sec3']) %}
  
          {% set grouped = specialEntries|group('section') %}
          {% for section, specialEntries in grouped %}
              &lt;h1&gt;{{ section }} - {{ section.handle }}&lt;/h1&gt;
          {% endfor %}   
  </code></pre>
  
Tags: <entries><sections><group>
Title: Get Section Handle From Group
ThreadText: # Get Section Handle From Group
  
  (Asked by: username_0 on 2017-02-20)
  
  I have a landing page on my site where I want to list a group of sections that have entries. I also need to access the section handle of that same group of sections.
  
  I am having problems getting the section handle for the sections.
  
  Currently I get an error back that says impossible to access attribute ("handle") on a string variable.
  
  ```
          {% set specialEntries = craft.entries.section(['sec1','sec2','sec3']) %}
  
          {% set grouped = specialEntries|group('section') %}
          {% for section, specialEntries in grouped %}
              <h1>{{ section }} - {{ section.handle }}</h1>
          {% endfor %}   
  
  ```
  
  **Tags:** entries, sections, group
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-02-21. Score: 1 | Accepted answer
  
  In your example, you're attempting to use a `SectionModel` instance as the key for your grouped entries. This is not possible.
  
  What actually happens behind the scenes is the `group` filter generates an object where the keys are the string value of the `SectionModel` instance [1], and the values are the `EntryModels` associated with that section.
  
  There are a few ways of achieving your desired outcome. Here's one possibility (not tested):
  
  ```
  {% set sections = craft.sections.getAllSections() %}
  {% set entries = craft.entries.section(['first', 'second', 'third']) %}
  {% set grouped = entries|group('section') %}
  
  {% for sectionHandle, sectionEntries in grouped %}
      {% set groupSection = false %}
      {% for section in sections %}
          {% if section.name == sectionHandle %}
              {% set groupSection = section %}
          {% endif %}
      {% endfor %}
  
      {% if groupSection %}
          <h1>{{ groupSection.name }} - {{ groupSection.handle }}</h1>
      {% endif %}
  {% endfor %}
  
  ```
  
  ---
  
  [1]: The [`SectionModel::__toString` method](https://craftcms.com/classreference/models/SectionModel#__toString-detail) returns the `name` attribute.
  
  > **Comments:**
  > **username_1**: Glad I could help   
  > **username_0**: Now that I have the sections outputting, I need to sort them.  Ideally by structureId.  I've tried applying supersort to the "grouped" query but I'm not getting the results I would expect.  Any advice?  
  > **username_1**: You should probably post a separate question for that.  
  
  ---
  
  