|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
sanderv Smarty n00b
Joined: 28 Jun 2010 Posts: 3
|
Posted: Mon Jul 05, 2010 9:01 am Post subject: Use custom function in loop |
|
|
I'm using the CodeIgniter framework with Smarty and use a custom Smarty function which returns config items:
Code: | {ci_config name='sitemap'} |
This call returns an multidimensional array containing the websites sitemap.
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:
Code: | {foreach {ci_config name='sitemap'} as $node}
<p>{$node.uri}</p>
{/foreach}
|
Any suggestions? Thanks! |
|
Back to top |
|
Gowser Smarty Pro
Joined: 19 Feb 2008 Posts: 104 Location: Nantes (France)
|
Posted: Mon Jul 05, 2010 10:19 am Post subject: |
|
|
Hello,
Maybe you can do that :
Code: |
{eval assign="ciConfigArray" var="ci_config name='sitemap'"}
{foreach $ciConfigArray as $node}
<p>{$node.uri}</p>
{/foreach}
|
Regards |
|
Back to top |
|
sanderv Smarty n00b
Joined: 28 Jun 2010 Posts: 3
|
Posted: Tue Jul 06, 2010 7:59 am Post subject: |
|
|
Gowser wrote: | Hello,
Maybe you can do that :
Code: |
{eval assign="ciConfigArray" var="ci_config name='sitemap'"}
{foreach $ciConfigArray as $node}
<p>{$node.uri}</p>
{/foreach}
|
Regards |
Ah darn, good idea, but doesn't seem to work. It just evaluates as a string assignment.
Thanks though!
Other suggestions? |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Tue Jul 06, 2010 12:55 pm Post subject: |
|
|
Code: | {ci_config name="sitemap" assign="map"}
{foreach $map as $node}
<p>{$node.uri}</p>
{/foreach} |
make sure your ci_config plugin supports the assign attribute. |
|
Back to top |
|
sanderv Smarty n00b
Joined: 28 Jun 2010 Posts: 3
|
Posted: Tue Jul 06, 2010 1:04 pm Post subject: |
|
|
mohrt wrote: | Code: | {ci_config name="sitemap" assign="map"}
{foreach $map as $node}
<p>{$node.uri}</p>
{/foreach} |
make sure your ci_config plugin supports the assign attribute. |
Awesome! This was it!
My custom function now assigns the value when it's an array and return the value when it's a simple integer or string value.
Thank you very much! |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|