Author Topic: [HTML bgcolor] setting bgcolor with __EVEN__  (Read 800 times)

0 Members and 1 Guest are viewing this topic.

Offline ClausVB

  • Administrator
  • Hero Member
  • *****
  • Posts: 566
    • Homepage: clausvb.de
[HTML bgcolor] setting bgcolor with __EVEN__
on: Mon, 26. August 2002 - 07:52:28
I made a little mistake. I did not use all vlibTemplates options:
Quote
-----Ursprüngliche Nachricht-----
Von: Kelvin Jones [mailto:[email protected]]
Date: Thursday, 22. August 2002 18:17
To: phd at clausvb.de
Subject: vlibTemplate

Hi Claus,

I was looking at your examples page for vlibTemplate, and I noticed the following bit of code:
        $mod = $i % 2;
        if ($mod == 0) 
            $bgcolor = 1;
        else 
            $bgcolor = 0;
        $tmpl->setVar(color, \"#F5F5DC\");
.. in one of your loop structures.
This is fine but I thought I would inform you of an easier way of doing alternative colours.
If you have the OPTION LOOP_CONTEXT_VARS set to 1 in your vlibIni.php file then you get a load of vars automatically set by vlibTemplate
to help with loop iterations. So you could do something like this in your loop:

<table>
    <tr>
        <th>Col1</th>
    </tr>
    <tmpl_loop name=loop1>
    <tr>
        <td bgcolor=\"#<tmpl_if name=__EVEN__>336699<tmpl_else>003366</tmpl_if>\">
            datal;skflkfjkldsgj
        </td>
    </tr>
    </tmpl_loop>
</table>

See the docs for more info, the OPTIONS section.
Regards,
Kelvin

I made the changes and it works.

Thanks Kelvin.
Last Edit: Thu, 08. March 2007 - 11:00:19 by ClausVB

NickM

  • Guest
[HTML bgcolor] setting bgcolor with __EVEN__
Reply #1 on: Sat, 12. October 2002 - 03:37:02
:D This little bit of info about  loop-specific variables is fantastic. I spent a lot of time (being only a beginner in PHP and templates) trying to figure out how to "get into" a loop to change colour etc. And now I have it...
I wish I had a look at this forum a little more closely a couple of days ago :oops: