Using LESS in CakePHP

Posted September 10th, 2011 • 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

Installation

Clone

Clone from github: in your plugin directory type:

$ git clone https://github.com/Hyra/less.git less

Submodule

Add as Git submodule: in your plugin directory type:

$ git submodule add https://github.com/Hyra/less.git less

Manual

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.

Usage

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

Features

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 ;)

Stay up to date

Want to know when a new post comes out and stay in the loop on tips, tricks and gotchas? Consider signing up for the Mindthecode newsletter.

Comments

Keep reading

May 26th, 2011 • 1 min read
In this short post I will show you how to get rid of a Git submodule
February 24th, 2012 • 1 min read
How to use sessions within your unit tests using PHPUnit and CakePHP
April 20th, 2016 • 8 min read
Inside React Native you can use the PanResponder to recognise multi-touch gestures as well as swipes and other touches that make native apps feel snappy and intuitive. But getting it up and running can feel daunting and borderline black magic. In this post I'll try and guide you through the process, hopefully demystifying it a bit and get you on track to awesomeness.