0

I need to get the IDs of particular segments in the URL, shown in bold (i.e. segments 2, 3 and 4):

/grid/strategic/corporate/uk/jim/tweets

They could also look like this (i.e. no category has been set):

/grid/-/-/-/jim/tweets

I'm assuming I would need a regex pattern match to do this and then use the {segment_category_ids} tag to pull them out in a list such as 37&342.

Not entirely sure how I should go about writing that for the settings though. I tried this:

^/[a-z-_0-9]*/[a-z-_0-9]*/[a-z-_0-9]*/[a-z-_0-9]*

Which works OK in a regexp checker but the I find that the tag {segment_category_ids} doesn't get rendered in the template.

How should I be providing this in the settings?

0

The regex option in Low Seg2Cat's settings is meant for something else: when set Low Seg2Cat will only set the {segment_n_category_x} variables when the URI matches the given pattern.

I take it you want to have access to those vars in all cases, so you should leave it blank.

If you do want to use the regex option, make sure you also add the delimiters to the pattern. In your case, that would mean the pattern could look something like this:

#^(/[\w-]+){4}$#
4
  • Thanks, Low. All I want to do is limit the number of segments that are set. There's an option to set ALL segments, and I assumed the reg would enable us to only set those that match the expression. Is the best way forward just to use conditionals as @andrew-fairlie suggested?
    – Russ Back
    Mar 6 '14 at 9:36
  • Depends on what you want to use. If you're using the regex, the extension will trigger (setting the vars) if there are exactly 4 segments. If you just want to use {segment_category_ids}, then leave the regex blank. It will return an empty string for an URI like /grid/-/-/-/jim/tweets and it will return something like 1&2&3 for an URI like grid/strategic/corporate/uk/jim/tweets, given that strategic, corporate and uk are valid category_url_titles and the other segments aren't.
    – Low
    Mar 6 '14 at 9:42
  • That's what I'm doing now. My concern would be that somebody could create a category called tweets and then we'd end up with the ID returned, when it's only IDs from segments 2, 3 and 4 which are category-related
    – Russ Back
    Mar 6 '14 at 10:42
  • Then I'd still leave the regex field empty and use {segment_2_category_id}&{segment_3_category_id}&{segment_4_category_id} instead.
    – Low
    Mar 6 '14 at 10:59
0

With LowSeg2 Cat could you do...

{if segment_2!="-"}{segment_2_category_id}&{/if}
{if segment_3!="-"}{segment_3_category_id}&{/if}
{if segment_4!="-"}{segment_4_category_id}{/if} {!-- No & here because it's the last segment --}

That should do the job.

1
  • I could, yes. But I wanted to understand the reg ex approach as it seems like a cleaner solution
    – Russ Back
    Mar 6 '14 at 7:51

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.