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

{section} loop parameter passing to a PHP function

 
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 -> Tips and Tricks
View previous topic :: View next topic  
Author Message
webvivekar
Smarty Rookie


Joined: 21 Oct 2003
Posts: 8

PostPosted: Wed Oct 22, 2003 11:00 am    Post subject: {section} loop parameter passing to a PHP function Reply with quote

When using {section} and looping thro the data items, I want to use a PHP function to format that data.
I need to get the return value from that PHP function and use modifiers for that item.
Code:

{section name=i loop=$customer}
   {$customer[i].cust_name|default:"Default Customer"}
   {$customer[i].cust_address|default:"Default Address"}
   {$customer[i].cust_joindate|date_format:"%b %d, %Y : %H:%M:%S %l"}
   {*
    Countries are in a database table. So only country id would be present
    in {$customer[i].cust_country}. For this I have a function called
   getcountryname() which accepts an integer param and returns the country name string.
   The problem is HOW TO pass the value in the loop to that PHP function.         
   *}
   {}
{sectionelse}
   Sorry. There are no customers found.
{/section}

---------------------------------------
I have tried out
Code:

{php}
   getcountryname({$customer[i].cust_country})  {* does not work *}
{/php}

Also {capture} and {insert} did not work.

Have anyone came across this situation?

BTW, I am using Smarty 2.5.0 (stable) for my project
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Wed Oct 22, 2003 11:09 am    Post subject: Reply with quote

{$smarty.section.customer.index}

RTM: http://smarty.php.net/manual/en/language.function.section.php and http://smarty.php.net/manual/en/section.property.index.php
Back to top
View user's profile Send private message Send e-mail Visit poster's website
webvivekar
Smarty Rookie


Joined: 21 Oct 2003
Posts: 8

PostPosted: Tue Oct 28, 2003 6:17 pm    Post subject: Reply with quote

I solved it by adding a "register_block" and calling it in the template.

Code:

{country}
{content}
{/country}


function country($content, &smarty)
{
......
}


Hope this helps some one.
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Wed Oct 29, 2003 1:41 am    Post subject: Reply with quote

why not just use your function as a modifer?

{$customer[i].cust_country|getcountryname}

More appropriate would be to send the actual name instead of the id in the first place.
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 -> Tips and Tricks 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