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

A nice list of items

 
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
z7q2
Smarty n00b


Joined: 17 Feb 2005
Posts: 1
Location: The New Jersey Shore

PostPosted: Thu Feb 17, 2005 2:07 pm    Post subject: A nice list of items Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website AIM Address MSN Messenger
Jek
Smarty n00b


Joined: 18 May 2009
Posts: 1

PostPosted: Mon May 18, 2009 2:49 pm    Post subject: Reply with quote

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