Using LESS in CakePHP

Posted May 15th, 2021 • 2 min read

I was a bit bored this morning with my previous Less component, so decided to rewrite the thing and added some new features such as caching. It's pretty straightforward and simple to set up. If you can't wait, the code is available here. For more information, read on.

This little helper converts your .less files into .css without relying on Node.js



Clone from github: in your plugin directory type:

$ git clone less


Add as Git submodule: in your plugin directory type:

$ git submodule add less


Download as archive from github and extract to app/plugins/less

Next, create a folder less in app/webroot/ and apply chmod 777 to it.


In your app_controller.php add the helper:

public $helpers = array('Less.Less');

Now every .less file from webroot/less will be converted to its .css equivalent in webroot/css

In your default.ctp layout you can just use echo $this->Html->css('your_css_file'); as you always do


Again, it's not much .. but I like simple things that make working on projects more fun, so it's all good.

I probably should update the helper again soon to make it work with CakePHP 2.0, but haven't decided when to make the switch yet. Then again, you guys can always fork and help out, of course ;)

More posts

May 15th, 2021 • 2 min read
Trying not to touch the arrow keys, not use the h-j-k-l too extensively either, work with A and I a lot, and generally trying not to cock things up too much by hitting the wrong commands.
May 15th, 2021 • 2 min read
Let me show you how to use a little helper so you can use LESS in your next CakePHP project
May 15th, 2021 • 2 min read
I'd like to use my first post to describe how I set up new projects in a simple way that works best for me.