One of the undying problems I have faced when coding PHP pages are CSS styles embedded into HTML, which is either echoed out - or returned as string(I usually separate pages into components, and each component will just return the html code that 'renders' it).
I have tried templating (Smarty in particular) and it works fine if you have static component placement and you have a tpl for each page, but I am using a single page system. So it means I need to have a tpl which in the end usually end up looking like this <div style="blah">{$placeholder}</div> just for that particular style. And for each different component, I will need a seperate tpl because there is no saying how many components a page will attach to itself.
Is there any solution to this? Can PHP variables be include in CSS stylesheets somehow so that there will be an automatic sync?
Seperating CSS from PHP scripts
Moderator: General Moderators
-
LonelyProgrammer
- Forum Contributor
- Posts: 108
- Joined: Sun Oct 12, 2003 7:10 am
Re: Seperating CSS from PHP scripts
Code: Select all
<?php
header("Content-type: text/css");
ob_start("ob_gzhandler");
$BodyFontColor = '#ffebcd';
$BodyFont = 'Tahoma,Genva,sans-serif';
$Title = '#e7e495';
$ImgUrl = '/cache/imgs/';
?>
/* Tag Specifics */
html,body{
height:100%;
font-family:<?php echo $BodyFont; ?>;
font-size:0.9em;
}
body{
background-color:#001115;
color:<?php echo $BodyFontColor; ?>;
}
p{
padding:0;
margin:0;
margin-top:8px;
padding-bottom:8px;
/* text-indent:35px; */
}
- Sekka
- Forum Commoner
- Posts: 91
- Joined: Mon Feb 18, 2008 10:25 am
- Location: Huddersfield, West Yorkshire, UK
Re: Seperating CSS from PHP scripts
I won't comment on the CSS problem as from what I can tell Zoxive has answered it very well.
One thing I will say is that you should easily be able to implement what you need with Smarty. I make very complicated content managed websites and Smarty has more than coped with my needs.
If you were having problems, I suggest you find some good tutorials on how to use Smarty to fit your needs.
One thing I will say is that you should easily be able to implement what you need with Smarty. I make very complicated content managed websites and Smarty has more than coped with my needs.
If you were having problems, I suggest you find some good tutorials on how to use Smarty to fit your needs.