Switchee icon indicating copy to clipboard operation
Switchee copied to clipboard

Allow capture group substitution in case content

Open Kindari opened this issue 14 years ago • 5 comments

This adds numeric and named capture group replacement to case content return data.

Example:

{exp:switchee variable="{segment_3}"}
    {!-- detect pagination, for example --}
    {case value="#^P(?P<page>\d+)$#|''"}
         We are on page #{switchee:page}
    {/case}
{/exp:switchee}

Kindari avatar Jan 11 '12 23:01 Kindari

Looks good, but could you please apply your patch to the develop branch instead? That's the beta version of Switchee and will be the next stable release.

Many thanks

https://github.com/croxton/Switchee/blob/develop/pi.switchee.php

croxton avatar Jan 12 '12 10:01 croxton

Hi, I did submit the request on the develop branch, as the top of this page says:

"Kindari wants someone to merge 1 commit into croxton:develop from kindari:develop".

Kindari avatar Jan 12 '12 23:01 Kindari

Sorry that's what happens when you've been up all night :)

I can see a possible problem with this when using nesting, as the nested switchee tags start {switchee ...}

It won't trip up the tag pair regex but it could increase recursion.

Maybe we need to use different prefix text for the captured values or add a parameter to specify the prefix.

Thoughts?

croxton avatar Jan 13 '12 18:01 croxton

I would either change the prefix (if so configurable prefix would be preferable for users) or I would change the pattern to check against switchee:, the difference between the nested tag and the captured variable being a colon syntax.

Kindari avatar Jan 13 '12 20:01 Kindari

Hmm, how about using parentheses {(page)} ?

I quite like that it echos the grouping syntax. What do you think?

croxton avatar Jan 20 '12 14:01 croxton