X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   Using foreach, how do you alternate product list Div's background color (https://forum.x-cart.com/showthread.php?t=49887)

Hyperdelicious 09-25-2009 11:22 AM

Using foreach, how do you alternate product list Div's background color
 
On the product list page... I would like products to appear with alternating background colors.. searched the forums but not finding a quick solution... the code is for products_list.tpl here is the snippet of code I'd like to edit:

<div class="products products-list">
{foreach from=$products item=product}

{assign var="url" value="product.php?productid=`$product.productid`& amp;cat=`$cat`&amp;page=`$navigation_page`"}
{if $featured eq 'Y'}
{assign var="url" value=$url|cat:"&amp;featured=Y"}
{/if}

<div class="item" style="background:#F9F0E9;text-align:center;vertical-align:middle;">

I'm thinking it should be as simple as creating an IF statement and adding some sort of array to determine odd even variable... sliding the IF variable=array show DIVx ELSE show DIVy... any ideas?

PhilJ 09-25-2009 12:30 PM

Re: Using foreach, how do you alternate product list Div's background color
 
Use cycle instead...
Code:

<div class="{cycle values="style1,style2"}">...</div>
Then...
Code:

.style1 { background: #ccc; }
.style2 { background: #eee; }

Etc.

Hyperdelicious 09-25-2009 01:18 PM

Re: Using foreach, how do you alternate product list Div's background color
 
Thanks, PhilJ... That's so much simpler than IF and ELSE statements... for future reference can you tell me how the cycle code works... or provide a link to resource... is that built into PHP, SMARTY, etc.?

PhilJ 09-25-2009 01:21 PM

Re: Using foreach, how do you alternate product list Div's background color
 
http://smarty.net/manual/en/language.function.cycle.php

Hyperdelicious 09-25-2009 01:35 PM

Re: Using foreach, how do you alternate product list Div's background color
 
awesome... thanks


All times are GMT -8. The time now is 03:44 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.