<p>That would require some sort of convention on your end which identifies what makes up a category/channel index page, as channels and categories don’t actually have an “index URL”.</p>

<p>For example you could decide that all sections’ index pages should have a URI that matches the section’s handle (not necessarily a good idea though, in the event that you want a URI that includes dashes). In that case you could do something like:</p>



<pre class="lang-twig prettyprint-override"><code>{% set segments = craft.request.getSegments() %}
{% if segments|length == 1 %}
    {% set section = craft.sections.getSectionByHandle(segments[0]) %}
    {% if section %}
        We’re on a section index!
    {% endif %}
{% endif %}
</code></pre>

<p>There is no corresponding function for getting a category group by its handle at this time, however.</p>

<p>A better approach might be to just leave it up to the templates to define whether they are supposed to be an index template. So in news/index.html, the template that you want to treat as the News index template, for example, you could put this:</p>

<pre class="lang-twig prettyprint-override"><code>{% set isIndex = true %}
</code></pre>

<p>Any layout templates that the index template extends will then have access to that <code>isIndex</code> variable.</p>

CC BY-SA 3.0
2014-09-01T11:47:57.170Z
As always, thank you Brandon. Just what I was after.
Mark Notton
CC BY-SA 4.0
2020-05-05T17:17:27.033Z
It would be good to highlight this in the docs. Maybe as a 'common gotchas' tip.
ponies
CC BY-SA 3.0
2014-08-15T16:46:48.110Z
2014-08-15T17:06:10.457Z
2014-08-15T17:06:10.457Z
Brandon Kelly
<p>In the <a href="https://craftcms.stackexchange.com/questions/1712/check-if-entry-is-defined-within-a-plugin-for-a-404-check">previous question</a> I asked for a way to detect the 404 page from a plugin. <a href="https://craftcms.stackexchange.com/users/9/brandon-kelly">Brandon</a> gave me a good starting point with <a href="https://craftcms.stackexchange.com/questions/1715/how-can-i-get-the-requested-entry-from-a-plugin">this answer</a>. However, I wondered what method I could use to also detect wether the user is on any category/channel index page?</p>

CC BY-SA 3.0
2014-08-13T18:01:59.383Z
I'm not entirely sure I understand what you're asking. Can you try to add an example or more specific details?
Tyler Willingham
<templating><sections>
How to check if on a channel/category index?
# How to check if on a channel/category index?

(Asked by: username_0 on 2014-08-13)

In the [previous question](https://craftcms.stackexchange.com/questions/1712/check-if-entry-is-defined-within-a-plugin-for-a-404-check) I asked for a way to detect the 404 page from a plugin. [Brandon](https://craftcms.stackexchange.com/users/9/brandon-kelly) gave me a good starting point with [this answer](https://craftcms.stackexchange.com/questions/1715/how-can-i-get-the-requested-entry-from-a-plugin). However, I wondered what method I could use to also detect wether the user is on any category/channel index page?

**Tags:** templating, sections

> **Comments:**
> **username_1**: I'm not entirely sure I understand what you're asking. Can you try to add an example or more specific details?  

---

## 1 answers

### Answer by username_2 on 2014-08-15. Score: 3 | Accepted answer

That would require some sort of convention on your end which identifies what makes up a category/channel index page, as channels and categories don’t actually have an “index URL”.
For example you could decide that all sections’ index pages should have a URI that matches the section’s handle (not necessarily a good idea though, in the event that you want a URI that includes dashes). In that case you could do something like:
{% set segments = craft.request.getSegments() %}
{% if segments|length == 1 %}
    {% set section = craft.sections.getSectionByHandle(segments[0]) %}
    {% if section %}
        We’re on a section index!
    {% endif %}
{% endif %}

There is no corresponding function for getting a category group by its handle at this time, however.
A better approach might be to just leave it up to the templates to define whether they are supposed to be an index template. So in news/index.html, the template that you want to treat as the News index template, for example, you could put this:
{% set isIndex = true %}

Any layout templates that the index template extends will then have access to that isIndex variable.

> **Comments:**
> **username_0**: As always, thank you Brandon. Just what I was after.  
> **username_3**: It would be good to highlight this in the docs. Maybe as a 'common gotchas' tip.  

---

