<p>You're close – this should work in Craft 3.x and 4.x (look at @obs answer for Craft 5):</p>
<pre><code>{% set blogSection = craft.app.sections.getSectionByHandle('blog') %}
{% set blogSectionEntryTypes = blogSection.getEntryTypes() %}

{% for entryType in blogSectionEntryTypes %}
    &lt;p&gt;{{ entryType.name }}&lt;/p&gt;
{% endfor %}
</code></pre>
<p>The reason why <code>craft.entries.section('blog').getEntryTypes()</code> didn't work is that <code>craft.entries</code> will actually create an <a href="https://docs.craftcms.com/v3/dev/element-queries/" rel="nofollow noreferrer">ElementQuery</a>, which is used to query for elements (e.g. entries).</p>
<p>When you use <code>craft.app.sections</code> or <code>craft.app.getSections()</code> (it doesn't really matter which variant you use, although the latter is a micro-optimisation in terms of performance) you're interacting with the <a href="https://docs.craftcms.com/api/v3/craft-services-sections.html" rel="nofollow noreferrer">Sections service</a>, which is what you need to use to work with sections and their entry types directly, rather than entries.</p>

CC BY-SA 4.0
2018-10-02T12:50:54.833Z
Thank you very much for the solution and for the explanation! I'll read up some more on how Craft works, particularly the parts you've mentioned.
Ryan Roberts
CC BY-SA 4.0
2023-09-10T12:37:57.253Z
How can the resulting list of entry types be sorted? I'm having no luck in Craft 4 using the `|sort` filter on these things.
Sandwich
CC BY-SA 4.0
2018-10-02T12:25:41.843Z
2024-04-29T14:24:31.190Z
2024-04-29T14:24:31.190Z
Mats Mikkel Rummelhoff
<p>For anyone coming here and looking for a solution for Craft 5:</p>
<p>It now works like that:</p>
<pre><code>{% set section = craft.app.entries.getSectionByHandle('blog') %}
{% set entryTypes = craft.app.entries.getEntryTypesBySectionId( section.id ) %}
</code></pre>
<p>Here are the docs: <a href="https://docs.craftcms.com/api/v5/craft-services-entries.html#entries" rel="nofollow noreferrer">https://docs.craftcms.com/api/v5/craft-services-entries.html#entries</a></p>

CC BY-SA 4.0
2024-04-27T19:29:17.200Z
2024-04-27T19:29:17.200Z
obs
<p>The following outputs all sections and their entry types, but I'm struggling to work out how I output only the entry types from the "blog" section.</p>

<pre><code>{% for section in craft.app.sections.allSections() %}
  &lt;h2&gt;{{ section.name }}&lt;/h2&gt;

  &lt;ul&gt;
    {% for type in section.getEntryTypes() %}
      &lt;li&gt;{{ type.name }}&lt;/li&gt;
    {% endfor %}
  &lt;/ul&gt;
{% endfor %}
</code></pre>

<p>I thought this would work</p>

<pre><code>{% for type in craft.entries.section('blog').getEntryTypes() %}
  &lt;p&gt;{{ type.name }}&lt;/li&gt;
{% endfor %}
</code></pre>

<p>But I've hit a wall because <code>getEntryTypes()</code> is an unknown method.</p>

<templating><craft3><sections><entry-type>
How can I list Entry Types of a single Section?
# How can I list Entry Types of a single Section?

(Asked by: username_0 on 2018-10-02)

The following outputs all sections and their entry types, but I'm struggling to work out how I output only the entry types from the "blog" section.
{% for section in craft.app.sections.allSections() %}
  {{ section.name }}

  
    {% for type in section.getEntryTypes() %}
      {{ type.name }}
    {% endfor %}
  
{% endfor %}

I thought this would work
{% for type in craft.entries.section('blog').getEntryTypes() %}
  {{ type.name }}
{% endfor %}

But I've hit a wall because getEntryTypes() is an unknown method.

**Tags:** templating, craft3, sections, entry-type


---

## 2 answers

### Answer by username_1 on 2018-10-02. Score: 3 | Accepted answer

You're close – this should work in Craft 3.x and 4.x (look at @username_3 answer for Craft 5):
{% set blogSection = craft.app.sections.getSectionByHandle('blog') %}
{% set blogSectionEntryTypes = blogSection.getEntryTypes() %}

{% for entryType in blogSectionEntryTypes %}
    {{ entryType.name }}
{% endfor %}

The reason why craft.entries.section('blog').getEntryTypes() didn't work is that craft.entries will actually create an ElementQuery, which is used to query for elements (e.g. entries).
When you use craft.app.sections or craft.app.getSections() (it doesn't really matter which variant you use, although the latter is a micro-optimisation in terms of performance) you're interacting with the Sections service, which is what you need to use to work with sections and their entry types directly, rather than entries.

> **Comments:**
> **username_0**: Thank you very much for the solution and for the explanation! I'll read up some more on how Craft works, particularly the parts you've mentioned.  
> **username_2**: How can the resulting list of entry types be sorted? I'm having no luck in Craft 4 using the `|sort` filter on these things.  

---

### Answer by username_3 on 2024-04-27. Score: 4

For anyone coming here and looking for a solution for Craft 5:
It now works like that:
{% set section = craft.app.entries.getSectionByHandle('blog') %}
{% set entryTypes = craft.app.entries.getEntryTypesBySectionId( section.id ) %}

Here are the docs: https://docs.craftcms.com/api/v5/craft-services-entries.html#entries


---

