We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Get contents of array from EE plugin

Development and Programming

Clive Portman's avatar
Clive Portman
83 posts
14 years ago
Clive Portman's avatar Clive Portman

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: 1315

I need to be able to access the three variables within the returned array in my template. Any ideas?

Thanks, Don

       
Clive Portman's avatar
Clive Portman
83 posts
14 years ago
Clive Portman's avatar Clive Portman

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;
       
Focus Lab Dev Team's avatar
Focus Lab Dev Team
1,129 posts
14 years ago
Focus Lab Dev Team's avatar Focus Lab Dev Team

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));
       
Clive Portman's avatar
Clive Portman
83 posts
14 years ago
Clive Portman's avatar Clive Portman

Sorted. Nice one.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.