You can also take a look in the EE source code or a module like Playa to see how they are doing it...
Apart from having a separate adding a tag to your module, you can manually search and parse those tags yourself. If you check the sourcecode for the channel module, you can find the following snippet of code used for the categories tag:
if (strpos($this->EE->TMPL->tagdata, LD.'/categories'.RD) !== FALSE)
{
if (preg_match_all("/".LD."categories(.*?)".RD."(.*?)".LD.'\/'.'categories'.RD."/s", $this->EE->TMPL->tagdata, $matches))
{
for ($j = 0; $j < count($matches[0]); $j++)
{
$cat_chunk[] = array($matches[2][$j], $this->EE->functions->assign_parameters($matches[1][$j]), $matches[0][$j]);
}
}
}
Instead of assigning the result to $cat_chunk
you can do you own parsing and replacement of that tag.
This does however add a lot of extra code because you wouldn't be able to use the $this->EE->TMPL->parse_variables
method anymore since you will have to parse everything manually (not just the var_pairs).
Something like this:
// Parse single variables
foreach ($this->EE->TMPL->var_single as $key => $val)
{
$value = isset($data[$key]) ? isset($data[$key]) : '';
$tagdata = $this->EE->TMPL->swap_var_single($key, $data[$key], $tagdata);
}
// Parse variable pairs
foreach ($this->EE->TMPL->var_pairs as $key => $val)
{
// parse categories
if (strpos($key, 'your_var_pair') !== FALSE)
{
// do something with the tag pair
}
}
In this case the $val
variable should hold your custom parameters.
That being said... the question you should be asking: "Is it all worth the trouble?". Will people (or you) ever use those parameters, because it does add a lot of overhead in the code. There are other tags you will need to parse manually like {switch=''}
, {count}
and {total_results}
.
My answer got a bit longer than I intended, but it IS a complex matter.
– Wouter