Hi. I’m writing a plugin but I’ve noticed a possible bug in EE->TMPL->parse_variables. When I pass an array that contains a tag pair two levels down and the template has two of those tag pairs and the first tag pair doesn’t contain all the tags of the second tag then the second tag pair will not display the tag that is missing from the first tag pair. To get a sense of what I mean here’s the output the code below, notice that the second line shows “{text} {text}” where “blue green” should be.
#00f blue #0f0 green - blue green
#00f #0f0 - {text} {text}Here is the function:
public function testEE() {
$tag = array(
'colour' =>
array(
array('data'=>array(
array('hex'=>'#00f','text'=>'blue'),
array('hex'=>'#0f0','text'=>'green')
)
)
),
);
$tag = array($tag);
$result = $this->EE->TMPL->parse_variables($this->EE->TMPL->tagdata, $tag);
return $result;
}and here is the template code:
{exp:test:testEE}
{colour}{data}{hex} {text} {/data}{/colour} - {colour}{data}{text} {/data}{/colour}
{/exp:test:testEE}
<br>
{exp:test:testEE}
{colour}{data}{hex} {/data}{/colour} - {colour}{data}{text} {/data}{/colour}
{/exp:test:testEE}Here’s a nice bodge to fix that example, but it will still have problems if there’s a tag pair further down the branch.
public function testEE() {
$tag = array(
'colour' =>
array(
array('data'=>array(
array('hex'=>'#00f','text'=>'blue'),
array('hex'=>'#0f0','text'=>'green')
)
)
),
);
$tag = array($tag);
return $this->parse_variables_fix($this->EE->TMPL->tagdata, $tag);
}
private function parse_variables_fix($tagdata,$tag) {
foreach ($tag[0] as $tag_name => &$tag_value) {
preg_match_all('/\{' . preg_quote($tag_name) . '\}[\s\S]+?\{\/' . preg_quote($tag_name) . '\}/',$tagdata,$matches);
for ($i=0;$i<count($matches[0]);$i+=1) {
$parsed = $this->EE->TMPL->parse_variables($matches[0][$i],$tag);
$tagdata = str_replace($matches[0][$i],$parsed,$tagdata);
}
}
return $tagdata;
}Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.