|
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 |
bhanu Smarty n00b
Joined: 25 Jun 2010 Posts: 1
|
Posted: Fri Jun 25, 2010 2:26 pm Post subject: last index of an foreach loop |
|
|
How to get last index value of foreach loop in smarty,i m new for smarty I have used this code but its not working
{foreach from=$cityList key=myId item=i name=foo}
{$i.location_name}{if $main_smarty.foreach.foo.last} {else}-{/if}
{/foreach}
i want that when their is last city name after this its come no - sign otherwise its like india-USA-Japan- but at last it come Japan-china
In .php i use
<?php
include_once('Smarty.class.php');
$main_smarty = new Smarty;
query to find citylist
$main_smarty->assign('cityList',$cityList);
?> |
|
Back to top |
|
bimal Smarty Elite
Joined: 19 Apr 2007 Posts: 423
|
Posted: Tue Jun 29, 2010 9:34 am Post subject: Try this |
|
|
May be you wanted this:
Code: | India - USA - Japan - China |
The template tags are:
Code: | {foreach from=$cityList key=myId item=i name=foo}
{$i.location_name}{if not $smarty.foreach.foo.last} - {/if}
{/foreach} |
And, I guess, your PHP looks like:
Code: | $cityList = array(
array(
'location_name'=> 'India',
),
array(
'location_name'=> 'USA',
),
array(
'location_name'=> 'Japan',
),
array(
'location_name'=> 'China',
),
);
$smarty->assign('cityList', $cityList); |
|
|
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
|