Jump to content

Archived

This topic is now archived and is closed to further replies.

SharkBait

Custom CSS with PHP

Recommended Posts

Hi,

I've added .css files to my AddHandler in my Apache config so that it will parse my CSS for php. Though I don't think its working.

[code=php:0]

/* CSS File */

body {
background-color: #fff;
margin: 0px auto;
text-align:center;
}

.
.
.
/* Custom Content CSS */

<?php
if(isset($CUSTOMSTYLE)) {
echo $CUSTOMSTYLE;
}
?>

.
.
.
/* EOF */
[/code]

And now the script I am trying to use...
[/code]
<?php

$CUSTOMSTYLE = "div.row {
clear:both;
padding-top: 10px;
}
div.row span.label {
float: left;
width: 100px;
text-align: right;
}
div.row span.formw {
float: right;
width: 335px;
text-align:left;
}";

require("includes/header.html");
// header.html has proper <link href="style.css" blahblah....

// Display form
?>
<form>
<div class="row">
<span class="label">Blah</span><span class="formw"><input type="text" /></span>
</div>
</form>

[/code]

Anyway when I use a plugin with Firefox to show me the css file for the page, it displays nothing under the /* Custom Content CSS */ where I thought it would echo.

Am I doing this wrong? Or can this not be done??

I don't want gigantic stylesheets and thought this would allow me to make the file itself small and be able to customize the 'content' pages when they are served.



Share this post


Link to post
Share on other sites
Yes, this can (and has been) done. You need to make sure you use
[code]<?php header('Content-type: text/css'); ?>[/code]
at the start of your file so the information is served correctly.

You may also want to use these headers also:
[code]<?php
header('Expires: Tue, 22 May 1988 03:20:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
?>[/code]

Ken

Share this post


Link to post
Share on other sites
[!--quoteo(post=375282:date=May 19 2006, 10:03 AM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ May 19 2006, 10:03 AM) [snapback]375282[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Yes, this can (and has been) done. You need to make sure you use
[code]<?php header('Content-type: text/css'); ?>[/code]
at the start of your file so the information is served correctly.

You may also want to use these headers also:
[code]<?php
header('Expires: Tue, 22 May 1988 03:20:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
?>[/code]

Ken
[/quote]

Now do I put that in the script that is wanting to use the custom CSS or does that go alongside the the header.html?

Share this post


Link to post
Share on other sites
I have this in survey.php

[code]

<?php
$CUST_STYLE = "div.row { \n
          clear:both; \n
                      padding-top: 10px;
                       }
                      ";

require("includes/header.html");

?>

HTML stuff here
<div class="row">
   Blah
</div>
[/code]

Now my stylesheet has the
[code]
if(isset($CUST_STYLE)) {
  echo nl2br($CUST_STYLE);
} else {
  echo "NOT FOUND";
}
[/code]
But when I look at the CSS it always echos NOT FOUND. I'm unsure why the $CUST_STYLE isnt being seen even though it declared before the require()

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.