Re: [SMARTY] Dynamic color
| From: | Monte Ohrt | Date: | Tue, 11 Feb 2003 16:48:28 +0000 |
| Subject: | Re: [SMARTY] Dynamic color | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-7642@lists.php.net to get a copy of this message | ||
From a conceptual point of view, the application should only tell the template the navigation pages, and the current page. Don't pass colors from the application, that is presentation information the template should control.
Now actually going about creating the navigation, I suppose there are several ways to do it. Navigation is probably reused on many pages, so it could have its own template, and get included on each page, such as:
{include file="navigation.tpl"}
Then the navigation template would display the navigation and highlight the current page:
{config_load file="colors.conf"}
...
{section name=nav loop=$pages}
<td bgcolor="{if $pages[nav].current}{#NavBG#}{else}{#NavBGHi#}{/if}">{$pages[nav].name}</td>
{/section}
...
Notice the colors are coming from a config file. That would be optional but a nice way to manage them. If you're using style sheets, then keep the colors there and use a dynamic class instead of bgcolor.
This method keeps all the presentation logic/colors in the template, and all the application logic in the application. If you want to change colors or the way navigation works, no need to change the application.
Monte
Erich C. Beyrent wrote:
Hi everyone,
I am new to PHP and Smarty, but here is what I want to do. Basically, I have a bunch of pages which all contain the same navigation menu (tables and links, nothing really fancy). I want to migrate this to a template, so that I only have to modify it once.
No problem, that all works fine. However, what I really want to do is make the background color of the <td> for the the current visible page be a different color than the rest of the cells on the menu. I am guessing I can do this with <td bgcolor={$bgcolor}><a href=#>Link 1</a></td>
What I don't know is where the logic should go to figure out which page is currently visible. Should this come from the PHP script, passing a variable to the smarty template $smarty->assign($bgcolor)
or should this logic be right in the template? Has anyone done something like this, and can you point me in the right direction?
Thanks!
-Erich-