public function extend()
{
/* Sample use
---------------------------------------------------------
{exp:stash:extend name="content" with="views:my_embed" stash:my_var="value"}
Or as a tag pair with an arbitrary 4th tagpart:
{exp:stash:extend:block name="content" with="views:my_embed"}
{stash:my_var}value{/stash:my_var}
{/exp:stash:extend:block}
--------------------------------------------------------- */
if (FALSE === ($with = $this->EE->TMPL->fetch_param('with', FALSE))) {
return;
}
$embed_params = array();
unset($this->EE->TMPL->tagparams['with']);
// have values other than embed name been passed in the "with" param? These should be passed as parameters to the embed:
$with = explode(' ', $with, 2);
// extract embed vars passed as params
foreach ($this->EE->TMPL->tagparams as $key => $val) {
if (strncmp($key, 'stash:', 6) == 0) {
$embed_params[] = $key . '="' . $val . '"';
}
}
// if this is a tag pair, construct an embed_extend tag and pass data enclosed by {stash:...} pairs to it
if ($this->EE->TMPL->tagdata) {
// construct the embed_extend tag
$this->EE->TMPL->tagdata = LD . 'exp:stash:embed_extend name="' . $with[0] . '"' . (isset($with[1]) ? ' ' . $with[1] : '') . ' ' . implode(" ", $embed_params) . RD . $this->EE->TMPL->tagdata . LD . '/exp:stash:embed_extend' . RD;
} else {
// construct the embed tag
$this->EE->TMPL->tagdata = LD . 'exp:stash:embed name="' . $with[0] . '"' . (isset($with[1]) ? ' ' . $with[1] : '') . ' ' . implode(" ", $embed_params) . RD;
}
// escape it?
if ((bool) preg_match('/1|on|yes|y/i', $this->EE->TMPL->fetch_param('escape'))) {
$this->EE->TMPL->tagdata = LD . 'stash:nocache' . RD . $this->EE->TMPL->tagdata . LD . '/stash:nocache' . RD;
}
// inject the embed into a variable / block
return $this->set();
}