2

I'm working on a module function where it will take the tagdata and send it through email. The tagdata can contain anything from simple strings to plugin or module tags.

I can't seems to find the clean solution without hacking the undocumented methods and probably unsupported and unstable and causing so many other problems.

template_file.html
{exp:my_module:send_mail}
  This is just an example with
  {exp:another_module:do_something_cool}
    some other cool stuffs
  {/exp:another_module:do_something_cool}.

  {global_variables} are working fine with the parse_global() function
{/exp:my_module:send_mail}

The code above will just send the whole $tagdata as it is without processing the {exp} tag inside. How do I process that {exp} tag before I send it through email?

1 Answer 1

3

Man, take a look at the function _parse_sub_template used on stash.

Mark Croxton, the developer of stash, cloned the tagdata and parsed it.

// clone the template object
$TMPL2 = $this->EE->TMPL;
unset($this->EE->TMPL);

// parse variables
$TMPL2->tagdata = $this->_parse_template_vars($TMPL2->tagdata);

// parse simple conditionals
$TMPL2->tagdata = $TMPL2->parse_simple_segment_conditionals($TMPL2->tagdata);
$TMPL2->tagdata = $TMPL2->simple_conditionals($TMPL2->tagdata, $this->EE->config->_global_vars);
// Remove any EE comments that might have been exposed before parsing tags
if (strpos($TMPL2->tagdata, '{!--') !== FALSE)
{
    $TMPL2->tagdata = preg_replace("/\{!--.*?--\}/s", '', $TMPL2->tagdata);
}
// parse tags, but check that there really are unparsed tags in the current shell
if (strpos($TMPL2->tagdata, LD.'exp:') !== FALSE)
{
    // parse tags
    $this->EE->TMPL = new EE_Template();
    $this->EE->TMPL->start_microtime = $TMPL2->start_microtime;
    $this->EE->TMPL->template = $TMPL2->tagdata;
    $this->EE->TMPL->tag_data   = array();
    $this->EE->TMPL->var_single = array();
    $this->EE->TMPL->var_cond   = array();
    $this->EE->TMPL->var_pair   = array();
    $this->EE->TMPL->plugins = $TMPL2->plugins;
    $this->EE->TMPL->modules = $TMPL2->modules;
    $this->EE->TMPL->module_data = $TMPL2->module_data;
    $this->EE->TMPL->parse_tags();
    $this->EE->TMPL->process_tags();
    $this->EE->TMPL->loop_count = 0;

    $TMPL2->tagdata = $this->EE->TMPL->template;
    $TMPL2->log = array_merge($TMPL2->log, $this->EE->TMPL->log);
}

$this->EE->TMPL = $TMPL2;   
unset($TMPL2);

// record if PHP is enabled for this template
$parse_php = $this->EE->TMPL->parse_php;

// parse advanced conditionals
$this->EE->TMPL->tagdata = $this->EE->TMPL->advanced_conditionals($this->EE->TMPL->tagdata);

// restore original parse_php flag for this template
$this->EE->TMPL->parse_php = $parse_php;

Please, improve this answer if you find more useful info.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.