I have a plugin constructed in the normal way that takes the placeholders inbetween it’s tag pair, and returns the data to the template using:
$this->return_data = $this->EE->TMPL->parse_variables($this->EE->TMPL->tagdata, $variables);However, it only works if i have the login in the constructor but not a function.
Say i have
public function __construct()
{
// Get to the EE superglobal
$this->EE =& get_instance();
$variables[] = array('jeff','bob, 'barry'');
$this->return_data = $this->EE->TMPL->parse_variables($this->EE->TMPL->tagdata, $variables);
}That works if you call {exp:plugin_name bob="stuff" barry="things"}{my_var1}{my_var2}{/exp:plugin_name} and it does indeed return the data.
But if i have the same code as the above but in it’s own function in the plugin class called
public function my_func()
{
}and i do:
{exp:plugin:my_func name bob="stuff" barry="things"}{my_var1}{my_var2}{/exp:plugin_name:my_func}{my_var1}{my_var2}it doesn’t output anything at all even though if i var_dump($this->return_data = $this->EE->TMPL->parse_variables($this->EE->TMPL->tagdata, $variables);) i can see that it has worked, the data in there is all that is within the tag pair and the data replacements have happened. It just doesn’t output it in the template!
Any ideas anyone?
Yes i still have the constructor in there and yes it still has $this->EE =& get_instance(); in it!
Hi johnwbaxter!
The difference is how the data is returned. If you are returning from the constructor, you use:
$this->return_data = $your_output_variable;to hold the final content.
If you are returning from a class method, like my_func(), you actually return the output data:
return $your_output_variable;Does that make sense?
Update: Here’s a link to the plugin documentation on Returning A Value.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.