Symfony 2.1 how to manage .less file by lessphp

After move to Symfony2.1 I was a little confused by using composer.phar. I want use less too – to easier write css code. After little research and test I see composer is a great tool! Some time after a figured out how to use lessphp. To save your time below it is my way:

Add to composer.json:

"require": {
"leafo/lessphp": "0.3.5"


from console:

php composer.phar update


in config.yml:

debug:          %kernel.debug%
use_controller: false
bundles:        [ ]
#java: /usr/bin/java
cssrewrite: ~
#    jar: %kernel.root_dir%/Resources/java/compiler.jar
#    jar: %kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar

file: %kernel.root_dir%/../vendor/leafo/lessphp/
apply_to: "\.less$"

and example of use in base.html.twig:

{% block stylesheets %}
{% stylesheets '@wdMyBundle/Resources/public/css/dom.less'
debug=false filter='lessphp' output='compile/css/dom.css' %}
{% endstylesheets %}
{% endblock %}

Have a nice day 🙂

Leave a Comment: