PDA

View Full Version : Using PHP to edit a style sheet on the fly


Bolch
01-12-2005, 13:15
Probably not the best title, but hopefully can explain better here.

Working on a site and thinking of using This (http://www.oswd.org/design/preview/id/2429) design. However on some pages I want the right hand side bar and others I don't. So as it's fixed width I'd need to change the width of the centre div based on wether the right column would be there or not.

Question is do I have 2 style sheets (1 that removes the side bar and widens the centre div when needed) and just use php to determine which style sheet to load. OR Can I set up a variable within the PHP script when I don't want the side bar and it edits the style sheet accordingly?

Vex
01-12-2005, 13:54
I'd use two style sheets, as you'll have caching issues if you modify the style sheet, plus if one visitor is looking at a particular page, and then another visitor looks at a different page while the first page is being loaded the style sheet could be in the middle of being updated, and you'd end up with the second page either failing to find the stylesheet, or just getting some of the content, etc... Could become a nightmare if the site has a lot of visitors.

I'd definately go for two style sheets.... :)

Bolch
01-12-2005, 14:17
Sorry, I didn't mean rewrite the actual file. Just change some of the code in the php file, essentially leaving out the that part of the CSS from the .css file and writing it direct to the HTML via the php.

I think 2 speadsheet solution is probably best, just wondered if anyone had anything similar setup and how they tackled it.

steford
01-12-2005, 15:22
Don't see PHP being a problem. You could write the whole stylesheet with PHP and include it with a parameter or have a seperate element hardcoded and rewrite that in PHP on the page itself depending on what kind of page you want. Or you could hardcode that also not needing PHP at all.