Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow capture group substitution in case content #1

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open

Allow capture group substitution in case content #1

wants to merge 1 commit into from

Conversation

Kindari
Copy link

@Kindari Kindari commented Jan 11, 2012

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}

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}
@croxton
Copy link
Owner

croxton commented Jan 12, 2012

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

@Kindari
Copy link
Author

Kindari commented Jan 12, 2012

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".

@croxton
Copy link
Owner

croxton commented Jan 13, 2012

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?

@Kindari
Copy link
Author

Kindari commented Jan 13, 2012

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.

@croxton
Copy link
Owner

croxton commented Jan 20, 2012

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants