Jump to content


Photo

Custom CSS with PHP


  • Please log in to reply
3 replies to this topic

#1 SharkBait

SharkBait
  • Members
  • PipPipPip
  • Advanced Member
  • 845 posts
  • LocationMetro Vancouver, BC

Posted 19 May 2006 - 04:28 PM

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.


/* CSS File */

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

.
.
.
/* Custom Content CSS */

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

.
.
.
/* EOF  */

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.





#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 19 May 2006 - 05:03 PM

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

You may also want to use these headers also:
<?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');
?>

Ken


#3 SharkBait

SharkBait
  • Members
  • PipPipPip
  • Advanced Member
  • 845 posts
  • LocationMetro Vancouver, BC

Posted 19 May 2006 - 05:53 PM

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

You may also want to use these headers also:
<?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');
?>

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?


#4 SharkBait

SharkBait
  • Members
  • PipPipPip
  • Advanced Member
  • 845 posts
  • LocationMetro Vancouver, BC

Posted 19 May 2006 - 07:44 PM

I have this in survey.php


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

require("includes/header.html");

?>

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

Now my stylesheet has the
if(isset($CUST_STYLE)) {
  echo nl2br($CUST_STYLE);
} else {
  echo "NOT FOUND";
}
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()






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users