Answers.Body: <p>Updated for Craft 4:</p>
  <pre><code>{% set enroll = craft.app.sections.getSectionByHandle('workshopEnrollments') %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-01-02T20:42:16.283Z
Answers.LastActivityDate: 2023-01-02T20:42:16.283Z
Answers.UserDisplayName: Mosswalker
Answers.Body: <p><strong>Original answer for Craft 2.x:</strong></p>
  <p><code>getSectionByHandle</code> doesn't return an array, but a single SectionModel - so you need to remove the <code>for</code> loop:</p>
  <pre><code>{% set enroll = craft.sections.getSectionByHandle('workshopEnrollments') %}
  
  {{ enroll.id }}
  </code></pre>
  <p><strong>Updated answer for Craft 4.x:</strong></p>
  <pre><code>{% set enroll = craft.app.sections.getSectionByHandle('workshopEnrollments') %}
  </code></pre>
  <p><strong>Updated answer for Craft 5.x:</strong></p>
  <pre><code>{% set enroll = craft.app.entries.getSectionByHandle('workshopEnrollments') %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2016-10-27T15:35:30.000Z
Answers.LastActivityDate: 2024-05-10T12:36:26.443Z
Answers.LastEditDate: 2024-05-10T12:36:26.443Z
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Body: <p>I need to access just the ID of a specific section.</p>
  
  <p>I do that like this and it works:</p>
  
  <pre><code>{% set enroll = craft.sections.getSectionByHandle('workshopEnrollments') %}
  </code></pre>
  
  <p>But when I do:</p>
  
  <pre><code>{% for e in enroll %} {{ e.sectionId }} {% endfor %}
  </code></pre>
  
  <p>or:</p>
  
  <pre><code>{% for e in enroll %} {{ e.id }} {% endfor %}
  </code></pre>
  
  <p>I get the error:</p>
  
  <pre><code>Impossible to access an attribute ("sectionId") on a string variable ("32")
  </code></pre>
  
  <p>However, when I view the variable inside my form what I actually see is exactly this </p>
  
  <pre><code>32Workshop EnrollmentsworkshopEnrollmentschannel1workshop-enrollments/_entry1
  </code></pre>
  
  <p>So my question is, how can I just display the id.  Both ".id" and ".sectionId" produce the same error mentioned above.  </p>
  
  <p>"32" is the id I want so it is the correct return, but this seems to show everything about it in a string and I need just the id. I am using getSectionByHandle because I have no other data to use in this particular view.</p>
  
  <p>Thanks for any help.</p>
  
Tags: <craft-pro>
Title: How do you get a section's ID
ThreadText: # How do you get a section's ID
  
  (Asked by: username_0 on 2016-10-27)
  
  I need to access just the ID of a specific section.
  
  I do that like this and it works:
  
  ```
  {% set enroll = craft.sections.getSectionByHandle('workshopEnrollments') %}
  
  ```
  
  But when I do:
  
  ```
  {% for e in enroll %} {{ e.sectionId }} {% endfor %}
  
  ```
  
  or:
  
  ```
  {% for e in enroll %} {{ e.id }} {% endfor %}
  
  ```
  
  I get the error:
  
  ```
  Impossible to access an attribute ("sectionId") on a string variable ("32")
  
  ```
  
  However, when I view the variable inside my form what I actually see is exactly this
  
  ```
  32Workshop EnrollmentsworkshopEnrollmentschannel1workshop-enrollments/_entry1
  
  ```
  
  So my question is, how can I just display the id. Both ".id" and ".sectionId" produce the same error mentioned above.
  
  "32" is the id I want so it is the correct return, but this seems to show everything about it in a string and I need just the id. I am using getSectionByHandle because I have no other data to use in this particular view.
  
  Thanks for any help.
  
  **Tags:** craft-pro
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2016-10-27. Score: 6 | Accepted answer
  
  **Original answer for Craft 2.x:**
  
  `getSectionByHandle` doesn't return an array, but a single SectionModel - so you need to remove the `for` loop:
  
  ```
  {% set enroll = craft.sections.getSectionByHandle('workshopEnrollments') %}
  
  {{ enroll.id }}
  
  ```
  
  **Updated answer for Craft 4.x:**
  
  ```
  {% set enroll = craft.app.sections.getSectionByHandle('workshopEnrollments') %}
  
  ```
  
  **Updated answer for Craft 5.x:**
  
  ```
  {% set enroll = craft.app.entries.getSectionByHandle('workshopEnrollments') %}
  
  ```
  
  
  ---
  
  ### Answer by username_1 on 2023-01-02. Score: 5
  
  Updated for Craft 4:
  
  ```
  {% set enroll = craft.app.sections.getSectionByHandle('workshopEnrollments') %}
  
  ```
  
  
  ---
  
  