processing .css files as php?

processing .css files as php?

Posted by: gnoodles
Posted on: 2006-09-03 02:38:00

I need to include some php code in my .css files (trying to avoid unnecessary hacks to account for browser inconsistencies). How do I tell the server to process .css files as php?

Thanks!

Re: processing .css files as php?

Posted by: seiler
Posted on: 2006-09-03 09:37:00

AddType application/x-httpd-php .css

Putting that in the .htaccess file would probably do the trick, but that's probably not the best way to do it. I never tried it, so I don't know if it would cause any problems or not.

Why not just put PHP code in your header that does what you want it to do, then includes the right .css file based on the results?

You could also look into CSS conditional statements. A Google search should bring up a bunch of tutorials.

Re: processing .css files as php?

Posted by: gnoodles
Posted on: 2006-09-03 11:31:00

Thanks for your help. Unfortunately, I actually knew that part. Perhaps a better way for me to have phrased my question would be:

Is there a way to change the site-wide configuration of PHP? .htaccess files work, but they have significant performance penalties, so I prefer to avoid them if at all possible.

Sorry my first question was kind of unclear, I posted it at something like 3am, so I wasn't at the top of my game right then...

Re: processing .css files as php?

Posted by: Atropos7
Posted on: 2006-09-03 12:06:00

Dynamic stylesheets in PHP or any CGI script are easy. You just need to send the right value for the content-type header. No messing around with server configuration necessary.

HTML document:

<link rel="stylesheet" type="text/css" href="style.php">


And then in style.php:

<?php Header('Content-Type: text/css') ?>
body {
color: black;
background-color: white;
}


cool Atropos | openvein.orgEdited by Atropos7 on 09/03/06 12:39 PM (server time).

Re: processing .css files as php?

Posted by: gnoodles
Posted on: 2006-09-03 12:27:00

That would be the logical thing to do, and it is what I have done as I've been developing my sites design. Now I'm ready to start actually developing a template for zen-cart, and I'm completely baffled by its completely uncommented php code. I'm far from a PHP guru, but I'm competent at it, but for the life of me, I've been unable to figure out how their file loading mechanism works. I make the changes to the code, and it just doesn't seem to find the files.

But regardless, it would actually be slightly prefereable to make the change. This way, I can go back & add some php to my older css files without haveing to edit each file that loads them. Given a choice, that would be the preferred solution.

Re: processing .css files as php?

Posted by: Atropos7
Posted on: 2006-09-03 13:48:00

I see what you mean, as they scan a directory for CSS files by extension.

So rename all the CSS files from filename.css to filename.php and add the call to Header()

Then modify /includes/templates/template_default/common/html_header.php

Search for the calls to get_template_dir and get_template_part.

For get_template_dir, change the value of '.css' to '.php'

For get_template_part, the last parameter should be 'php' instead of 'css'

Works for me.


cool Atropos | openvein.org

Re: processing .css files as php?

Posted by: gnoodles
Posted on: 2006-09-03 21:40:00

I had tried that yesterday, but I guess my brain wasn't at 100% when I tried to get this working at about 2am or so last night. When I had a chance to try it again after a good night sleep, I was able to get it working.

Thanks!
Mike

Tags: css filesphp codeunnecessary