tags:

views:

30

answers:

2

I'm using the CodeIgniter framework with Smarty and use a custom Smarty function which returns config items:

{ci_config name='sitemap'}

This call returns an multidimensional array containing the websites sitemap:

$config['sitemap'] = array('dashboard' => array('uri'=>'dashboard',
                                                'title'=>'Dashboard'),
                           'photos' => array('uri'=>'photos',
                                             'title'=>'Photos'));

Note: this is an example array, the actual array will be really multilevel

I would like to loop this array but how do I use the return value in a loop construct?

Although wrong, this is what i would like to achieve:

{foreach {ci_config name='sitemap'} as $node} 

<p>{$node.uri}</p> 

{/foreach} 

Any suggestions? Thanks!

Note: I'm using the latest Smarty 3 RC2.

A: 

use section to loop through the array instead of foreach. There should be examples in the documentation to help you deal with the looping issue.
http://www.smarty.net/manual/en/language.function.section.php

Thomas Winsnes
yes, but the looping itself is not the problem, it's how to capture the return value of the custom function and use that in a smarty construct...
Sander Versluys
ow and also, section is decrecated in Smarty 3. thanks though ;-)
Sander Versluys
A: 

User 'mohrt' from the Smarty forum posted following good anwser:

{ci_config name="sitemap" assign="map"} 
{foreach $map as $node} 

<p>{$node.uri}</p> 

{/foreach}

also make sure your ci_config plugin supports the assign attribute

http://www.smarty.net/forums/viewtopic.php?t=17655

Just make sure to assign the variable in your custom function or plugin with the Smarty instance.

Thanks mohrt!

Sander Versluys