I have a string of piped category ID's which represent all the categories which are selected for any given page.

Within my page, I now need to check the input of the chosen categories.

For example, I have {segment_category_ids_piped} (I'm using Low Seg2Cat) - this returns "3|5|6|14".

In my category loop, I now need to check the checkbox if the category exists. The code I have at the moment is :

<li><input type="checkbox" {if segment_category_ids_piped *= cat_id}checked="checked"{/if}><a href="#" title="{cat_name}">{cat_name}<span>({entry_count})</span></a></li>

The problem is that it's treated as a literal string, so if I loop through my categories, it's showing cat_id 1 and 4 as being selected, because they are represented in the string for 14.

I'm presuming that a regular expression would be needed here, but I'm at a bit of a loss as to the syntax (RegExp has never been a strong point of mine!).


1 Answer 1


Try this:

{if segment_category_ids_piped ~ '/\b'.cat_id.'\b/'}

Note: this works for pipe-separated IDs (numbers). If you're looking for pipe-separated strings or text, you'd be better off using this:

{if piped_text ~ '/(^|\|)'.text.'(\||$)/'}

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.