|
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 |
z7q2 Smarty n00b
Joined: 17 Feb 2005 Posts: 1 Location: The New Jersey Shore
|
Posted: Thu Feb 17, 2005 2:07 pm Post subject: A nice list of items |
|
|
Given
Code: | $items = array( "Pots", "Owls", "Buicks", "Pepper" ); |
and
Code: | $smarty->assign("items", $items); |
this template code
Code: | Items:{assign var="item_counter_max" value=$items|@count}{counter
start=0 print=false assign="item_counter"}{foreach
item=item from=$items}{counter}{if
$item_counter < $item_counter_max}{if
$item_counter > 1},{/if}{else}{if
$item_counter_max > 1} and{/if}{/if} {$item}{/foreach}<br> |
will make you a nicely formatted list:
Code: | Items: Pots, Owls, Buicks, and Pepper |
|
|
Back to top |
|
Jek Smarty n00b
Joined: 18 May 2009 Posts: 1
|
Posted: Mon May 18, 2009 2:49 pm Post subject: |
|
|
But why not so?
Code: | //{if count($items)}
{foreach from=$items item=item name=anchor}
{if $smarty.foreach.anchor.first}Items: {/if}
{if $smarty.foreach.anchor.last} and {/if}
{$item}
{if !$smarty.foreach.anchor.last}, {else}.{/if}
{/foreach}
//{/if} |
Excuse me for my english. |
|
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
|