I have some code inside a global snippet that I only want to display on a blog listing page. So the allowed URL types could be:

  • /blog
  • /blog/P10
  • /blog/category/crackers
  • /blog/author/skeletor

I do not want the code to display on the individual blog post pages (/blog/my-post-title).

So the pseudo-conditional would be:

  • If segment_1 equals "blog" AND

    • segment_2 is empty
    • OR segment_2 is pagination
    • OR segment_2 equals "category"
    • OR segment_2 equals "author"

The pagination is the part that's tripping me up. I know I can use Switchee to use regexes, but it doesn't let me use advanced AND/OR and () operators to string cases together. Something like:

{if segment_1 == 'blog' AND (segment_2 == '#^P(\\d+)$#' OR segment_2 == 'category' OR segment_2 == 'author' OR segment_2 == '')}

Is there an add-on that will let me use regexes inside advanced conditionals, or is there another way of doing it altogether?

  • You can do things like AND stackoverflow.com/a/469951 I'd continue w/ Switchee or does it not allow this?
    – Natetronn
    Dec 21, 2012 at 19:26
  • It's not just AND/OR though, it's also the () which groups the segment_2 conditionals together. So it would be something like {if segment_1 == 'blog' AND (segment_2 == '#^P(\\d+)$#' OR segment_2 == 'category' OR segment_2 == 'author' OR segment_2 == '')}
    – kmgdev
    Dec 21, 2012 at 19:32

1 Answer 1


You can actually nest Switchee tags with a special syntax, so this should work for you:

{exp:switchee variable="{segment_1}" parse="inward"}
    {case value="blog"}
        {switchee variable="{segment_2}" parse="inward"}
            {case value="#^P(\d+)$#|''|category|author"}
            .. display your stuff ...
  • 1
    I did not know that! Great, answer - thanks!
    – kmgdev
    Dec 21, 2012 at 19:35
  • I just tried it with a slightly different syntax, but the content is displayed on the single-entry blog post pages. Any idea why?
    – kmgdev
    Dec 21, 2012 at 20:01
  • My bad, I was using "case" instead of "variable" inside the {exp:switchee} tag.
    – kmgdev
    Dec 21, 2012 at 20:34
  • 1
    Glad you sorted it. Dec 21, 2012 at 23:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.