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:

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

lessphp:
file: %kernel.root_dir%/../vendor/leafo/lessphp/lessc.inc.php
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 🙂

Incoming search terms:

  • lessphp symfony2
  • symfony2 lessphp
  • symfony lessphp

Leave a Comment: