<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>

CC BY-SA 4.0
2020-06-26T12:33:45.483Z
Thanks James. That works! I had tried something similar to no avail....

`{% if entry.section.name == 'projects' %}`
Tom Byrom
CC BY-SA 4.0
2020-06-26T12:57:08.523Z
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>`
James Smith
CC BY-SA 4.0
2020-06-27T17:59:38.123Z
Good to know, appreciate that
Tom Byrom
CC BY-SA 4.0
2020-06-26T11:43:24.673Z
2020-06-26T11:43:24.673Z
James Smith
<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>

<craft3><entries>
How to check an entry is in a section within a for loop
# 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 James. 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  

---

