Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Aiheen aloitti: Sir Osis of Liver - elokuu 10, 2014, 04:16:23 IP

Otsikko: Alternating background?
Kirjoitti: Sir Osis of Liver - elokuu 10, 2014, 04:16:23 IP
 >:( Can't get this to work -



echo ' <tr class=', $message['alternate'] == 0 ? 'windowbg' : 'windowbg2' ,'>';



Where does $message['alternate'] come from?
Otsikko: Re: Alternating background?
Kirjoitti: Suki - elokuu 10, 2014, 04:35:22 IP
From Sources/Display.php::prepareDisplayContext()

'alternate' => $counter % 2,

Its just a shortcut to get a series of 0 and 1 for every message been displayed. $counter been the number assigned to the message while been retrieved.
Otsikko: Re: Alternating background?
Kirjoitti: Sir Osis of Liver - elokuu 10, 2014, 04:41:31 IP
 
Am modifying the comment section of a gallery mod, so it doesn't connect to /Sources/Display.php.  Guess I'll use yet another workaround -



if ($message['alternate'] == 0)
$message['alternate'] = 1;
elseif ($message['alternate'] == 1)
$message['alternate'] = 0;



 
Otsikko: Re: Alternating background?
Kirjoitti: Suki - elokuu 10, 2014, 04:46:18 IP
It really depends on what you're going to do, I just answered your question.

There are multiple ways to get an alternative, the simpliest and easiest would be to add your own $counter var.

Assuming you have an array of messages:

$myOwnCounter = 0;

foreach ($myMessages as $message)
{
    $myOwnCounter++;

    $cssBacjground= ($myOwnCounter % 2 == 0) ?  'white': 'black';

// Use $cssBackground

}
Otsikko: Re: Alternating background?
Kirjoitti: Sir Osis of Liver - elokuu 10, 2014, 04:58:04 IP
Just trying to alternate the bg between windowbg and windowbg2, as in display template.  It currently has this -



echo '<tr class="windowbg">';



Will tinker with your counter code.  Thanks.