Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Using foreach, how do you alternate product list Div's background color

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 09-25-2009, 11:22 AM
  Hyperdelicious's Avatar 
Hyperdelicious Hyperdelicious is offline
 

Senior Member
  
Join Date: Sep 2002
Location: In the Middle of Nowhere
Posts: 138
 

Default 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?
Reply With Quote
  #2  
Old 09-25-2009, 12:30 PM
 
PhilJ PhilJ is offline
 

X-Guru
  
Join Date: Nov 2002
Posts: 4,094
 

Default 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.
__________________
xcartmods.co.uk
Reply With Quote

The following user thanks PhilJ for this useful post:
Hyperdelicious (09-25-2009)
  #3  
Old 09-25-2009, 01:18 PM
  Hyperdelicious's Avatar 
Hyperdelicious Hyperdelicious is offline
 

Senior Member
  
Join Date: Sep 2002
Location: In the Middle of Nowhere
Posts: 138
 

Default 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.?
Reply With Quote
  #4  
Old 09-25-2009, 01:21 PM
 
PhilJ PhilJ is offline
 

X-Guru
  
Join Date: Nov 2002
Posts: 4,094
 

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

http://smarty.net/manual/en/language.function.cycle.php
__________________
xcartmods.co.uk
Reply With Quote
  #5  
Old 09-25-2009, 01:35 PM
  Hyperdelicious's Avatar 
Hyperdelicious Hyperdelicious is offline
 

Senior Member
  
Join Date: Sep 2002
Location: In the Middle of Nowhere
Posts: 138
 

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

awesome... thanks
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 03:30 PM.

   

 
X-Cart forums © 2001-2020