- beanmac
Hi all,
When creating a page in drupal 6, I want to be able to change the background color of the page dynamically without hard-coding the actual node or alias name of the page. Currently, our site hard-codes the node/number on the page.tpl.php inside our theme, but this is not the best approach if we want to create new pages with different backgrounds. Does anyone have any ideas?
Thanks,
- Bryant
Something you may consider is creating a jQuery script which will change the background color via css. jQuery is included by default with drupal 5.
Something like this could be in a js file:
$(document).ready(function(){
$("#changeColor").click(function(){
$("#container").css('background-color', '#903');
});
});
If you put this in a .js file and include it in your drupal page.tpl.php file, every time the "changeColor" div is clicked, the "container" div will have the css background-color: #903; property applied to it.
Let me know if this works for you.
I did figure out a work around. I enabled the path module to use URL aliases. Since we have only 5 different background colors we want to use, I figure we can hard code only 5 specific url category names in the page.tpl.php file and I can parse out url to get the category name and apply the class that corresponds to the css background color. I did a proof of concept and got it working. I don't really know how to use jQuery, but I wouldn't mind learning more about it. This can definitely be an enhancement down the road. Let me know if using jQuery would be easier than this approach.
Thank you for your help.
- Bryant
I figured out a better way without worrying about the URL aliases. I used taxonomy to create the list terms and each term has a color or class name in it synonym. That way, each page will have to choose a term, and with that term has a color synonym to make the background dynamic. Only things that are hardcoded is the css and the taxonomy terms.
Thanks again for the jQuery approach.
- Bryant