I have a list of teasers on any given page, and say I wanted the first teaser background to be gray, the next to be green, the third to be gray again, and so on. Can that be done while creating the templates, or is that something that needs to be coded deeper in the module?

Comments

jrglasgow’s picture

you could put the teaser each in a div with a different class like so:

<?php
// you have to set a $_SESSION variable so on the next teaser we can switch
if (!isset($_SESSION['teaser_class'])) {
  // there is not a teaser_class variable, so set it
  $_SESSION['teaser_class'] = 'odd';
}
// add the div with the class you want
?>
<div class="teaser_<?php print $_SESSION['teaser_class'] ?>">
<?php print $teaser ?>
</div>
<?php
// now we need to switch the class
if ($_SESSION['teaser_class'] == 'odd') {
  // the current class is 'odd' so we need to switch it to 'even'
  $_SESSION['teaser_class'] = 'even';
}
else {
 // the current class is not 'odd' so we need to switch to 'odd'
  $_SESSION['teaser_class'] = 'odd';
}
?>

then you need to theme your site to have different backgrounds for 'teaser_even' and 'teaser_odd' classes

joepril’s picture

Assigned: joepril » Unassigned

I think I suck at explaining what I've done. Lemme try again. So I have just one teaser template for multiple items. I then use Views to sort the various items onto separate pages, while they all use the same teaser template. On those views pages (based on price), is there a way to make the teasers alternate background colors. Don't know if what you explained would work in that situation.

jrglasgow’s picture

I understood your request as you just explained it. The code I provided above should work as you desire, I haven't tested the code, but I believe it will work.