2

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

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?

I have also gone down another path which follows:

Module:

Class main{
 function data(){
      blah blah blah 
      $this->return_user(14);
 }
 function return_user($var){
      return '<p>'.$var.'</p>';
 }

} 

Template:

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

{exp:main:return_user} returns <p></p>, but not <p>14</p>.

Any ideas?

1

EE 1.7 is pretty old but still fresh in my memory.

You need to use the global object $TMPL, which has a tagdata property that contains the data/string.

Example code

function data(){
    global $TMPL;

    $vars = array();
    $vars[LD.'data'.RD] = 'foo';
    $vars[LD.'data2'.RD] = 'foo2';

    $TMPL->tagdata = str_replace(array_keys($vars), array_values($vars) $TMPL->tagdata);

    return $TMPL->tagdata;
}
| improve this answer | |
  • So like this: function data(14){ global $TMPL; $TMPL->tagdata = $level; return $TMPL->tagdata; } Because thats prints "Array" when I print out in EE code: {exp:class:method} – JMP Jan 8 '13 at 20:32
  • You can't do it like that if $level is an array. You need to specify each variable one by one. Or do you want to parse out the array contents dynamically? is it a multidimensional array? – Victor Gutierrez Jan 8 '13 at 21:10
  • Ive changed it to no longer require an array. So $level is just a string. – JMP Jan 8 '13 at 22:43
  • Here is my two main methods. "data" works and returns an array, Im pushing the contents I need from "data" to Userlevel so that I can just call {exp:data:Userlevel} and return the string. pastebin.com/MNXPfPtn – JMP Jan 8 '13 at 23:09
  • Any have time to check out my pastebin? – JMP Jan 9 '13 at 20:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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