Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Use custom function in loop

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
sanderv
Smarty n00b


Joined: 28 Jun 2010
Posts: 3

PostPosted: Mon Jul 05, 2010 9:01 am    Post subject: Use custom function in loop Reply with quote

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
View user's profile Send private message
Gowser
Smarty Pro


Joined: 19 Feb 2008
Posts: 104
Location: Nantes (France)

PostPosted: Mon Jul 05, 2010 10:19 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
sanderv
Smarty n00b


Joined: 28 Jun 2010
Posts: 3

PostPosted: Tue Jul 06, 2010 7:59 am    Post subject: Reply with quote

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! Wink

Other suggestions?
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Tue Jul 06, 2010 12:55 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
sanderv
Smarty n00b


Joined: 28 Jun 2010
Posts: 3

PostPosted: Tue Jul 06, 2010 1:04 pm    Post subject: Reply with quote

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! Wink
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP