Best way to determine whether in post index or post show

Answered

Comments

4 comments

  • Official comment
    David Kortleven

    You can find the index post of a post_type as follows:

    site.[[post_type_name]]_index

    So to see if you are on the index post of the post_type called "projects":

    {% if post == site.projects_index %}
    Do stuff
    {% endif %}
    Comment actions Permalink
  • Edwin Bos

    I kinda fixed it by using the post.slug property, "index-projecten" in my case.

    It doesn't feel right though, so the question still stands.

    0
    Comment actions Permalink
  • Edwin Bos

    Thanks, I use it like this to determine if current page is a "project show" page:

    {% if post.content_type.name == 'project' and post != site.projects_index %}
    0
    Comment actions Permalink
  • David Kortleven

    That's a nice and valid approach!

    0
    Comment actions Permalink

Please sign in to leave a comment.