Answers.Body: <p>Check against <code>entry.section.handle</code>:</p>
  <pre><code>{% for entry in craft.entries.authorId(authorIds).orderBy('dateCreated desc').all() %}
                          
        {% if entry.section.handle == 'projects' %}
  
           Do something
      
        {% elseif entry.section.handle == 'events' %}
  
           Do something different
  
        {% endif %}
  
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-06-26T12:33:45.483Z
Answers.Text: Thanks James. That works! I had tried something similar to no avail....
  
  `{% if entry.section.name == 'projects' %}`
Answers.UserDisplayName: Tom Byrom
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-06-26T12:57:08.523Z
Answers.Text: If you're ever in doubt about what variables are available to you, a handy trick is to dump out the key names in your template like this: `<pre>{{ dump(entry.section|keys) }}</pre>`
Answers.UserDisplayName: James Smith
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-06-27T17:59:38.123Z
Answers.Text: Good to know, appreciate that
Answers.UserDisplayName: Tom Byrom
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-06-26T11:43:24.673Z
Answers.LastActivityDate: 2020-06-26T11:43:24.673Z
Answers.UserDisplayName: James Smith
Body: <p>I need to display different information depending on the section the entry comes under when I'm displaying all entries within a loop.</p>
  <p>Use case - I have a feed which will pull in all entries such as 'Projects' and 'Events' both are sections set up as channels.</p>
  <p>I need to display different information relating to each Entry on the front end as they have different fields.</p>
  <p>So I need to check if the entry belongs to 'projects' or 'events' within the loop. I can't seem to achieve it.</p>
  <p>Current code:</p>
  <pre><code>{% for entry in craft.entries.authorId(authorIds).orderBy('dateCreated desc') %}
                          
        {% if entry in craft.entries.section('projects') %}
  
        Do something
      
        {% elseif entry in craft.entries.section('events') %}
  
        Do something different
  
        {% endif %}
  
  {% endfor %}
  </code></pre>
  <p>This displays nothing? Any help?
  Thanks</p>
  
Tags: <craft3><entries>
Title: How to check an entry is in a section within a for loop
ThreadText: # How to check an entry is in a section within a for loop
  
  (Asked by: username_0 on 2020-06-26)
  
  I need to display different information depending on the section the entry comes under when I'm displaying all entries within a loop.
  
  Use case - I have a feed which will pull in all entries such as 'Projects' and 'Events' both are sections set up as channels.
  
  I need to display different information relating to each Entry on the front end as they have different fields.
  
  So I need to check if the entry belongs to 'projects' or 'events' within the loop. I can't seem to achieve it.
  
  Current code:
  
  ```
  {% for entry in craft.entries.authorId(authorIds).orderBy('dateCreated desc') %}
                          
        {% if entry in craft.entries.section('projects') %}
  
        Do something
      
        {% elseif entry in craft.entries.section('events') %}
  
        Do something different
  
        {% endif %}
  
  {% endfor %}
  
  ```
  
  This displays nothing? Any help?
  Thanks
  
  **Tags:** craft3, entries
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-06-26. Score: 6 | Accepted answer
  
  Check against `entry.section.handle`:
  
  ```
  {% for entry in craft.entries.authorId(authorIds).orderBy('dateCreated desc').all() %}
                          
        {% if entry.section.handle == 'projects' %}
  
           Do something
      
        {% elseif entry.section.handle == 'events' %}
  
           Do something different
  
        {% endif %}
  
  {% endfor %}
  
  ```
  
  > **Comments:**
  > **username_0**: Thanks username_1. That works! I had tried something similar to no avail....  `{% if entry.section.name == 'projects' %}`  
  > **username_1**: If you're ever in doubt about what variables are available to you, a handy trick is to dump out the key names in your template like this: `<pre>{{ dump(entry.section|keys) }}</pre>`  
  > **username_0**: Good to know, appreciate that  
  
  ---
  
  