|
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 |
webvivekar Smarty Rookie
Joined: 21 Oct 2003 Posts: 8
|
Posted: Wed Oct 22, 2003 11:00 am Post subject: {section} loop parameter passing to a PHP function |
|
|
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 |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
|
Back to top |
|
webvivekar Smarty Rookie
Joined: 21 Oct 2003 Posts: 8
|
Posted: Tue Oct 28, 2003 6:17 pm Post subject: |
|
|
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 |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Wed Oct 29, 2003 1:41 am Post subject: |
|
|
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 |
|
|
|
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
|