Hi,
I’ve got this plugin which returns an array - how do I access the contents of the array within my template?
At the moment, I’m getting the following:
Severity: Notice
Message: Array to string conversion
Filename: libraries/Template.php
Line Number: 1315I need to be able to access the three variables within the returned array in my template. Any ideas?
Thanks, Don
Hmmm. Similar questions on this topic seem to go unanswered as well…
After digging around in other plugins, this seems to work:
foreach ($this->EE->TMPL->var_single as $key => $val) {
if ($key == 'location')
{
$this->EE->TMPL->tagdata = $this->EE->TMPL->swap_var_single($key, $weather['location'], $this->EE->TMPL->tagdata);
}
if ($key == 'weather')
{
$this->EE->TMPL->tagdata = $this->EE->TMPL->swap_var_single($key, $weather['weather'], $this->EE->TMPL->tagdata);
}
if ($key == 'image')
{
$this->EE->TMPL->tagdata = $this->EE->TMPL->swap_var_single($key, $weather['image'], $this->EE->TMPL->tagdata);
}
}
$this->return_data = $this->EE->TMPL->tagdata;That code works. But it’s “the old way”.
Take a look at these docs: http://ellislab.com/expressionengine/user-guide/development/usage/template.html#parsing_variables
Ultimately you should be able to do something like this:
$this->return_data = $this->EE->TMPL->parse_variables($this->EE->TMPL->tagdata, array($weather));Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.