I have a section set up to display contents based on category URL information and it works great. However, when I do a search, the search result URL has a unique value in segment_4 that doesn't fit into any of the designated categories:


In this case I would prefer to hide the conditional content, but I am not sure how to work that segment_4 value into a conditional since it will change with each search return.

I am thinking along the lines of only display the content if segment_4 is not a number.

2 Answers 2


I'm not sure I understood you, but the conditional you mentioned is:

{if !(segment_4 ~ "/^\d+$/") } the `segment_4` isn't a number{/if}

I hope it helps.

  • 1
    Could be slightly more elegant with {if segment_4 ~ '/^\D*$/'} as \D matches any non-digit.
    – Low
    Feb 19, 2015 at 21:21
  • My bad! You're right! Please, update it, @Low!
    – Sobral
    Feb 20, 2015 at 0:29

If you don't already have URL Helper ( https://devot-ee.com/add-ons/url-helper ) or Seg2Cat ( http://gotolow.com/addons/low-seg2cat/ ) installed, I'd suggest installing URL Helper (they both use the same syntax; URL Helper has a few more variables, so that's the one I'd recommend getting; both are free).

Once you've got that, you'll have access to a couple of new variables you can use for some conditionals to test whether or not segment 4 (or any other segment) is a valid category or not.

I suspect you could use something like this...

{if "{last_segment_category_id}" == ""}The last segment is not a category{/if}

... and work out a way to achieve what you're looking for.

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.