Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-09-01T11:47:57.170Z
Answers.Text: As always, thank you Brandon. Just what I was after.
Answers.UserDisplayName: Mark Notton
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-05-05T17:17:27.033Z
Answers.Text: It would be good to highlight this in the docs. Maybe as a 'common gotchas' tip.
Answers.UserDisplayName: ponies
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-15T16:46:48.110Z
Answers.LastActivityDate: 2014-08-15T17:06:10.457Z
Answers.LastEditDate: 2014-08-15T17:06:10.457Z
Answers.UserDisplayName: Brandon Kelly
Body: <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>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-08-13T18:01:59.383Z
Comments.Text: I'm not entirely sure I understand what you're asking. Can you try to add an example or more specific details?
Comments.UserDisplayName: Tyler Willingham
Tags: <templating><sections>
Title: How to check if on a channel/category index?
ThreadText: # 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. [username_2](https://craftcms.stackexchange.com/users/9/username_2) 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:
  
  ```twig
  {% 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:
  
  ```twig
  {% 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 username_2. Just what I was after.  
  > **username_3**: It would be good to highlight this in the docs. Maybe as a 'common gotchas' tip.  
  
  ---
  
  