foreach - For each loop in ExpressionEngine template? -


i've created ee plugin function returns array. e.g.

function things(){     return array(         array(             'name'=>'bob',             'age'=>40         ),         array(             'name'=>'mary',             'age'=>50         )     ); } 

i cannot find way loop through array vanilla ee template tags. can plugins return strings? not possible or overlooking simple? i'd like:

{foreach {things} }     name: {name}     age: {age} {/foreach} 

your array structured correctly, need use template class' parse variables method. great thing method allows nest many levels deep if (allowing tag pairs within tag pairs within tag pairs), , {count} , {total_results} automatically.

so in plugin:

function things() {     $things = array(         array(             'name'=>'bob',             'age'=> '40'         ),         array(             'name'=>'mary',             'age'=> '50'         )     );     return $this->ee->tmpl->parse_variables($this->ee->tmpl->tagdata, $things); } 

then in template:

{exp:my_plugin:things}     name: {name}     age: {age} {/exp:my_plugin:things} 

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -