Hello,
I have a template which looks like the following:
{iterate param='value'}
{items} … {/items}
{/iterate}
I’m trying to find the {iterate} var pair using the following, but it doesn’t work:
if (preg_match_all("/".LD."iterate param=['\"](.*)['\"]".RD."(.*)".LD.SLASH.'iterate'.RD."/s", $tagdata, $matches)) {
}
Any suggestions? I’m sure it’s just a matter of tweaking the regex.
Thanks for your help.
Mike
Hiya,
If you are creating your own plugin then the way I usually throw out values is in this sort of way :
foreach ($TMPL->var_single as $key => $val)
{
$title = $query->row['title'];
if ($key == "title")
{
$tagdata = $TMPL->swap_var_single($key, $title, $tagdata);
}
}
$this->return_data .= $tagdata;
}
That kind of thing. Does that help at all?
Best wishes,
Mark
There is already a function to grab the data between var pairs, IIRC it is named get_data_between_var_pairs().
Also there is a function that mistakenly you may assume replaces the contents of the var pair with data, but it doesn’t. You will have to use a str_replace or regex replace alternative to achieve it - the function just removes the {var_pair}… {/var_pair} tags.
Mark, your suggestion is a good way of handling var_single variables, but not var_pair.
Daniel, I tried to use $TMPL->fetch_data_between_var_pairs and $TMPL->swap_var_pairs, but unfortunately neither could match my template. I found the correct regex pattern to use:
if (preg_match_all("/\{iterate param=['\"](.*)['\"]\}(((\s+)?.*(?<!\{\/iterate\}))*)\{\/iterate\}/", $tagdata, $matches, PREG_SET_ORDER)) {
foreach ($matches as $match) {
$var_pair = $match[0];
$param = $match[1];
$var_pair_tagdata = $match[2];
}
}
Hope this is some help to anyone else that has a problem swapping var_pair variables.
Thanks for your help guys, Mike
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.