Matching one URL segments always works fine but is possible to match more than one?

For example this works:

{if segment_2 == "page"}nav-expanded nav-active{/if}

But this does not:

{if segment_2 == "page1" OR "page2"}nav-expanded nav-active{/if}

I tried all operators and conditionals possible and nothing works for me from the official docs here: https://docs.expressionengine.com/latest/templates/conditionals.htm

I need to match more than one page (not at the same time) but no operators I test like equal, or, and seems to work with segments. I'm trying to avoid having to create a whole new {if segment_2} for every single sub-menu page

Maybe this is not possible?

3 Answers 3


I would use this to check multiple pages:

{if "page1|page2" *= segment_2} active {/if}
  • 1
    While the other solutions also work, this is the correct answer. I don't want to keep adding segment_2 for each page, but just once and specify the pages to match. Your code is the clean short solution to this. Thank you!
    – nibb11
    Commented Aug 15, 2018 at 8:06
  • You are most welcome. This is actually contains key *= Commented Aug 15, 2018 at 11:04

You can try below code.

{if segment_2 == "page1" || segment_2 == "page2"} nav-expanded nav-active {/if}

I hope this will works for you.

  • I tried this before posting here. || is basically the same operator as OR, I think I don't use segment_2 twice but I will test this again.
    – nibb11
    Commented Aug 15, 2018 at 7:29
  • You can use segment_2 twice in if condition, there is no problem with that. I am sure this will definitely works for you. Commented Aug 15, 2018 at 7:53


{if segment_2 == "page1" OR  segment_2 == "page2" }nav-expanded nav-active{/if}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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