Using PHP variables in your CSS file in Symfony

I would like to use PHP variables in my CSS files, but I do not want to load the entire Symfony stack for every file download. Anyone have any recommendations and / or plugins for managing their CSS files in Symfony?

+3
source share
2 answers

but for this you don’t need a full symfony stack (unless 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 can add appropriate headers (text / css) with a header in php.

+5
source

Here is one good plugin that tries to manage and / or combine your assets:

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

Here is their description:

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

In addition, since it is compiled, you can use simple PHP if the variables are inserted into the same file.

+2
source

All Articles