Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using PHP variables in your CSS file in Symfony

I'd love to use PHP variables in my CSS files but I don't want to load up the whole Symfony stack for each file load. Any one have any best practices and/or plugins to manage their CSS files in Symfony?

like image 290
thrashr888 Avatar asked Aug 28 '26 12:08

thrashr888


2 Answers

but you dont need full symfony stack for that ( except if you need some internal symfony state / variable ).

You just use

<link rel="stylesheet" type="text/css" media="screen" href="/css/mycss.php" />

and then you can use php inside your css. you could add appropriate headers (text/css) with header in php.

like image 75
deresh Avatar answered Aug 30 '26 01:08

deresh


Here's one good Plugin that tries to manage and/or combine your assets:

http://www.symfony-project.org/plugins/sfCombinePlugin

Here's their description:

Combines multiple JavaScript and CSS files into one JavaScript and one CSS file at runtime, in order to minimize the number of HTTP requests required to render a given page. This plugin works in distributed environments, supports asset version keys, and is highly customizable.

Also, since it's compiled, you may be able to use simple PHP as long as the variables stick within the same file.

like image 32
thrashr888 Avatar answered Aug 30 '26 03:08

thrashr888



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!