Download the PHP package elboletaire/less-cake-plugin without Composer
On this page you can find all versions of the php package elboletaire/less-cake-plugin. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package less-cake-plugin
Less parser plugin for CakePHP 3.X
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 but if, for any reason, it fails, will fallback to the less.js parser both included by this plugin (this way you'll see any errors on screen).
Installation
You can install this plugin into your CakePHP application using composer.
The recommended way to install composer packages is:
After installing it you'll need to load it on your bootstrap.php
file:
And load it into your (App)Controller:
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:
You can compile multiple files if you pass an array:
Or you can load your less files with the HtmlHelper sending the files to the CSS block:
Note the
?
at the end of the filename. It's used to force the .less extension. Otherwise it would be overwriten tostyles.less.css
by the UrlHelper.
And then parse all your files using the fetch method:
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:
If you want to use the less.js parser directly, instead of just as a fallback, or you want to use the #!watch method, you can do it so by setting the js parser to 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:
Options
Beside the options for less.js and less.php parsers you can set three options to the helper:
cache
: default's to true. If disabled, the output will be raw CSS wrapped with<style>
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.
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:
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:
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.