Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

Adding a different class name with foreach

 
Post new topic   Reply to topic    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
susawx
Smarty n00b


Joined: 18 Jun 2010
Posts: 1

PostPosted: Fri Jun 18, 2010 8:25 pm    Post subject: Adding a different class name with foreach Reply with quote

HI! I have this code and I want to generate a different class name to the <tr> tag like extra1, extra2, extra3, etc How can I do so?

{* Extra Fields *}
{foreach from=$extrafields item=extras}
<tr class="????">
<td><strong>{$extras.title}:</strong></td>
<td>
{if isset($extras.value)}
{foreach key=key item=item from=$extras.value}
{$item|nl2br}<br />
{foreachelse}
{$extras.value}
{/foreach}
{/if}
</td>
</tr>
{/foreach}

Thanks!!!
Back to top
View user's profile Send private message
jpiercemaine
Smarty Regular


Joined: 24 Sep 2009
Posts: 82

PostPosted: Fri Jun 18, 2010 8:52 pm    Post subject: a Reply with quote

if you are just going to name them based on the iteration : 1,2,3,4,5,etc...

Code:

{* Extra Fields *}
{foreach from=$extrafields item=extras name=myextras}
<tr class="extra{$smarty.foreach.myextras.iteration}">
<td><strong>{$extras.title}:</strong></td>
<td>
{if isset($extras.value)}
{foreach key=key item=item from=$extras.value}
{$item|nl2br}<br />
{foreachelse}
{$extras.value}

_________________
~ jpierce
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> General 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