Jump to content

Styling foreach loop


Sonu2007

Recommended Posts

I have following code which generates Configurable Options each per line in table. but i want to show 2 Configurable Options per line but not sure how to do it.

							<table width="100%" border="0" align="center" cellpadding="3" cellspacing="0" class="data2" style="border-top:0px;border:1px solid #ddd">
						<th colspan="2" align="center">Configurable Options</th>
						{if $configurableoptions}
							  {foreach from=$configurableoptions item=configoption}
								<tr><td class="odd3" style="padding-left:10px" >{$configoption.optionname}:</td><td style="padding-left:10px">{if $configoption.optiontype eq 3}{if $configoption.selectedqty}{$LANG.yes}{else}{$LANG.no}{/if}{elseif $configoption.optiontype eq 4}{$configoption.selectedqty} x {$configoption.selectedoption}{else}{$configoption.selectedoption}{/if}</td></tr>										
							{/foreach}
						</table>

Link to comment
Share on other sites

the basic way to do it would be like this...

 

{assign brian ['left','right','left','right']}
<table border=1 width=25%>
   {foreach $brian as $item}
       {if $item@first}<tr>{/if}
           <td>{$item}</td>
       {if $item@last}</tr>
       {else}
           {if $item@iteration is div by 2}</tr><tr>{/if}
       {/if}
   {/foreach}
</table>

ignore the assign line of code (I just needed an array to output) and the adding of a border and width to the table (as that's for my output only) - concentrate on what's inside the foreach loop and adjust to your code accordingly.

 

6efSgRA.png

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated