PHPackages                             elboletaire/less-cake-plugin - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. elboletaire/less-cake-plugin

AbandonedArchivedCakephp-plugin[Parsing &amp; Serialization](/categories/parsing)

elboletaire/less-cake-plugin
============================

Less parser plugin for CakePHP

v1.7.1(10y ago)1668.9k↑111.1%9[4 issues](https://github.com/elboletaire/less-cake-plugin/issues)[1 PRs](https://github.com/elboletaire/less-cake-plugin/pulls)1Apache-2.0PHP

Since Jan 12Pushed 9y ago4 watchersCompare

[ Source](https://github.com/elboletaire/less-cake-plugin)[ Packagist](https://packagist.org/packages/elboletaire/less-cake-plugin)[ RSS](/packages/elboletaire-less-cake-plugin/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (9)Dependencies (4)Versions (14)Used By (1)

Less parser plugin for CakePHP 3.X
==================================

[](#less-parser-plugin-for-cakephp-3x)

[![Build status](https://camo.githubusercontent.com/bbd7e1d0a8acdb2f1b1b271a380dc46a3b0c6abfb4434f5ca992c021e8d2c3ef/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f656c626f6c6574616972652f6c6573732d63616b652d706c7567696e2e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/elboletaire/less-cake-plugin)[![Code coverage](https://camo.githubusercontent.com/3679335a97e652ff7a11397bd2a6660808a94f1046d454079230775fb00755fb/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f656c626f6c6574616972652f6c6573732d63616b652d706c7567696e2e7376673f7374796c653d666c61742d737175617265)](https://coveralls.io/github/elboletaire/less-cake-plugin)[![License](https://camo.githubusercontent.com/b8ac9bcc35327802ce216ab716cc1ae0d537bf79b67ac7f02aac0dad46dad539/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f656c626f6c6574616972652f6c6573732d63616b652d706c7567696e2e7376673f7374796c653d666c61742d737175617265)](https://github.com/elboletaire/less-cake-plugin/blob/master/LICENSE)[![Latest Stable Version](https://camo.githubusercontent.com/07f12cc90171475c90e19dbd32424853646c63ab445f0dcd6a9ba475b9e46dce/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f656c626f6c6574616972652f6c6573732d63616b652d706c7567696e2e7376673f7374796c653d666c61742d737175617265)](https://github.com/elboletaire/less-cake-plugin/releases)[![Total Downloads](https://camo.githubusercontent.com/692598c5eaf3b605c8c50d10595c9bbe684fa1e8c1c04abcde1b17a291619eb7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f656c626f6c6574616972652f6c6573732d63616b652d706c7567696e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/elboletaire/less-cake-plugin)[![Code Climate](https://camo.githubusercontent.com/567e32a869bc4cc08fb1ce9b30ea7b27b52150c367d36fe2a8efc218931b39bf/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636c696d6174652f6769746875622f656c626f6c6574616972652f6c6573732d63616b652d706c7567696e2e7376673f7374796c653d666c61742d737175617265)](https://codeclimate.com/github/elboletaire/less-cake-plugin)

This plugin has a helper to help you parsing `.less` files in CakePHP 3.0 applications.

By default, the helper will parse all less files to CSS files using [less.php](https://github.com/oyejorge/less.php) but if, for any reason, it fails, will fallback to the [less.js](http://lesscss.org/#download-options) parser both included by this plugin (this way you'll see any errors on screen).

Installation
------------

[](#installation)

You can install this plugin into your CakePHP application using [composer](http://getcomposer.org).

The recommended way to install composer packages is:

```
composer require elboletaire/less-cake-plugin

```

After installing it you'll need to load it on your `bootstrap.php` file:

```
Plugin::load('Less');
```

And load it into your (App)Controller:

```
public $helpers = ['Less.Less'];
```

Usage
-----

[](#usage)

By default it will compress files using the php parser with cache enabled. This will fill your `css` folder with a bunch of files starting with `lessphp_`used for the cache. I recommend you adding these files to your `.gitignore` file in order to prevent commiting them:

```
lessphp_*

```

Basically, you give the helper a less file to be loaded (usually from `/less`directory) and it returns the html link tag to the compiled CSS:

```
echo $this->Less->less('less/styles.less');
// will result in something like...

```

You can compile multiple files if you pass an array:

```
echo $this->Less->less(['less/myreset.less', 'less/styles.less']);
// They will be compiled in the same file, so the result will be the same as the previous one

```

Or you can load your less files with the HtmlHelper sending the files to the CSS block:

```
$this->Html->css('/less/styles.less?', ['block' => true, 'rel' => 'stylesheet/less']);
```

> Note the `?` at the end of the filename. It's used to force the .less extension. Otherwise it would be overwriten to `styles.less.css` by the UrlHelper.

And then parse all your files using the fetch method:

```
echo $this->Less->fetch();
echo $this->fetch('css');
```

By default, any less file found will be removed from the css block and thus, not printed.

You can also pass any option to both less.js and less.php parsers:

```
echo $this->Less->less('less/styles.less', [
    'js' => [
        // options for lessjs (will be converted to a json object)
    ],
    'parser' => [
        // options for less.php parser
    ],
    // The helper also has its own options
]);
// Same if using the fetch method, but the options are as first param:
echo $this->Less->fetch(['js' => []]);
```

If you want to use the less.js parser directly, instead of just as a fallback, or you want to use the [\#!watch](http://lesscss.org/usage/#using-less-in-the-browser-watch-mode) method, you can do it so by setting the js parser to development:

```
echo $this->Less->less('less/styles.less', ['js' => ['env' => 'development']]);
```

This will output all the links to the less files and the needed js files to parse the content only using the less.js parser.

> Note: if there is an error in the php parser the helper will fallback to the js parser so you can see the errors in screen. If, for any reason, you can't see those errors, check the `error.log` file in the logs folder; it will contain any error generated by the less.php parser.

To load less files inside plugins you can use plugin notation:

```
echo $this->Less->less('Bootstrap.less/styles.less');
// or...
echo $this->Less->less('/Bootstrap/less/styles.less');
// both will load plugins/Bootstrap/webroot/less/styles.less file
```

### Options

[](#options)

Beside the options for [less.js](http://lesscss.org/#client-side-usage-browser-options) and [less.php](https://github.com/oyejorge/less.php#lessphp) parsers you can set three options to the helper:

- `cache`: default's to true. If disabled, the output will be raw CSS wrapped with `` tags.
- `tag`: default's to true. Whether or not return the code with its proper tag (with cache enabled will be a link tag, whilst without cache will be a style tag).
- `less`: default's to `/bootstrap/js/less.min`. You can use this var to set a custom less.js file.

```
// Get the link to the resulting file after compressing
$css_link = $this->Less->less('less/styles.less', [
    'tag'   => false
]);

// Get the compiled CSS (raw)
$compiled_css = $this->Less->less('less/styles.less', [
    'cache' => false,
    'tag'   => false
]);
```

As a default setting of the LessHelper, all the CSS generated by the less.php parser is compresed. To override this set `compress` to `false` in the less.php parser options:

```
echo $this->Less->less('less/styles.less', [
  'parser' => ['compress' => false]
]);
```

### Modify Vars

[](#modify-vars)

Last but not least, if you want to overwrite any variable set on your less files you can use the `$modify_vars` param:

```
echo $this->Less->less(['less/styles.less'], [], ['bgcolor' => 'magenta']);
echo $this->Less->fetch([], ['bgcolor' => 'magenta']);
// Will overwrite any @bgcolor found in styles.less to #f0f
```

License
-------

[](#license)

```
Copyright 2015 Òscar Casajuana (a.k.a. elboletaire)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
imitations under the License.

```

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance15

Infrequent updates — may be unmaintained

Popularity39

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~48 days

Recently: every ~41 days

Total

11

Last Release

3664d ago

Major Versions

v1.6.1 → 2.x-dev2015-04-06

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/153305?v=4)[Òscar Casajuana](/maintainers/elboletaire)[@elboletaire](https://github.com/elboletaire)

---

Top Contributors

[![elboletaire](https://avatars.githubusercontent.com/u/153305?v=4)](https://github.com/elboletaire "elboletaire (51 commits)")

---

Tags

cake-plugincakephpcakephp3csshelperlessparser-pluginpluginpluginparsercsscakephpless

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/elboletaire-less-cake-plugin/health.svg)

```
[![Health](https://phpackages.com/badges/elboletaire-less-cake-plugin/health.svg)](https://phpackages.com/packages/elboletaire-less-cake-plugin)
```

###  Alternatives

[sabberworm/php-css-parser

Parser for CSS Files written in PHP

1.8k191.2M65](/packages/sabberworm-php-css-parser)[scotteh/php-dom-wrapper

Simple DOM wrapper to select nodes using either CSS or XPath expressions and manipulate results quickly and easily.

1471.9M10](/packages/scotteh-php-dom-wrapper)[mishal/iless

Less.js port to PHP

4737.0k3](/packages/mishal-iless)[hexydec/htmldoc

A token based HTML document parser and minifier. Minify HTML documents including inline CSS, Javascript, and SVG's on the fly. Extract document text, attributes, and fragments. Full test suite.

2610.3k3](/packages/hexydec-htmldoc)[trentrichardson/cakephp-shrink

Compiles, combines, and minifies javascript, coffee, less, scss, and css

1619.3k](/packages/trentrichardson-cakephp-shrink)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
