Search code examples
phpexpressionengine

Expressionengine Module return array


So Im returning an array of all the information I need from my function, but I can seem to figure out how to parse through the array once I get to the templete.

Module:

Class main{
 function data(){
      blah blah blah 
      return $array;
 }
} 

Template:

{exp:main:data}{data}{/exp:main:data} 

{data} returns “Array”

How can I parse through this in EE code or is there another to parse this variable?


Solution

  • You need to pass your array of data to the parse_variables() method of the TMPL (template) class.

    return $this->EE->TMPL->parse_variables($this->EE->TMPL->tagdata, $data);

    Note also that if you're only returning a single row of data, that will need to live as its own array inside $data. This can be done quickly by passing your array as array($data).

    I'd suggest reading the module development documentation as well.

    Lastly, you might want to post future EE-related questions over on the new ExpressionEngine StackExchange.