Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion pi.switchee.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public function Switchee()
// check for a string contained within hashes #regex#
if (preg_match('/^#(.*)#$/', $case_value))
{
if (preg_match($case_value, $var))
if (preg_match($case_value, $var, $case_vars))
{
// we've found a match, grab case content and exit loop
$this->return_data = substr($tagdata, $starts_at, $ends_at - $starts_at);
Expand All @@ -164,6 +164,19 @@ public function Switchee()
{
$this->EE->TMPL->log_item("Switchee: regex match: case '{$case_value}' matched variable '{$var}'");
}

if ( count($case_vars) > 1)
{ // pattern used capture groups, make them available as variables
foreach( $case_vars as $case_var_key => $case_var_value)
{
if ($debug)
{
$this->EE->TMPL->log_item("Switchee: captured variable: '{switchee:{$case_var_key}}' => '{$case_var_value}'");
}

$this->return_data = preg_replace("#{switchee:{$case_var_key}}#", $case_var_value, $this->return_data);
}
}

break 2;
}
Expand Down