Less is an extension that allows developers to compile LESS files using the native JavaScript compiler. LESS can be compiled both client-side using less.js and server-side using lessc, the extension supports both compilers.
Thanks to my friend Sam Stenvall (negge) for providing me with his version of the server-side compiler.
You can read about how to setup and use the extension from its README on GitHub.
Total 20 comments
Enable auto-compiling if you've enabled the component.
// CSS files if (Yii::app()->hasComponent('less')) { Yii::app()->less->files = array('themes/frontend/less/p3.less' => 'themes/frontend/css/p3.css'); Yii::app()->less->register(); } else { // fallback $cs->registerCssFile(Yii::app()->theme->baseUrl . '/css/p3.css'); }https://github.com/Crisu83/yii-less/edit/master/README.md
Finally I found the solution... The problem was the command executing the compiler. It seems to have some wrong syntax the the less version I have installed. I changed the command and now it works like a charm.
I also found out that the compiled files need to have the file extension ".css" because ".less" is not interpreted as css in the html header. So may be you could change this in your README.
Thanks for your help.
Hmm, use
echos or Yii::log() to see in detail what happens and which command gets executed. Sorry, I got no more ideas ...?!Yes I am still registering in the layouts html header. Should I try to register it in the init() function or where would you do it?
I've created a post in the forum. May be we could discuss my problem in this thread.
Do you still register the compiler in the layout?
Just a shot in the dark...
I do not get any errors... The less files are just not compiled. When I compile the files manually everything works fine but when I run the application the less files are not generated and I get the standard layout (without less generated css). Are there some possible problems you could imagine?
Which errors do you get? The way you described works fine for me.
I've got some problems with using different less files for showing different styles in different areas of one application. With client side mode I used this code in the header of protected/views/layouts/main.php:
Now I changed to server side mode and can't get it to work. With the code from client side mode it didn't work so I changed to only register less in the layouts/main.php's header. I also tried to use multiple instances of the compiler but this seems not to work too. The code therefore looked like that:
And of course I changed the register code to register lessArea1 and lessArea2. But it was always the same, I had always the same style in both areas.
Does anyone have an idea what I'm doing wrong or an hint how I could do this better?
If it does not work from your webserver, but on the Terminal with your user, I would have guessed directory permissions. But if they are adjusted ... ?!
May you can try to execute the command as webserver, like:
and see if you find some errors there.
Hello Schmunk, thanks for your help so far. I still receive a "Failed to compile file" error. After this error message, the commands are displayed. I copy these into the terminal, and it works perfect. But not from within yii (or lets say not by the apache). The Css folder and also the styes.css are writeable.
Any ideas?
Here's my less compiler setup for OSX.
Find your node :)
You can try the setup in Phundament, download install, copy
config/local-dist.phptoconfig/local.php, give write permission to the css folder, don't forget to register the less compiler in your main layout.If you get an error, paste the command into Terminal to receive the full error output.
Does anybody have experience with this Less extension on OSX? I have installed node.js and Less (global). I can run a less command from the Terminal and create a CSSfile from a LESSfile. So it should work. I manage it to compile client side (this has nothing to do with npg, I know. But it means that I have installed the extension in Yii correctly). But I do not get it to work server side from within this extension. I think it is a problem with the path settings. What paths do you guys (on OSX) have there in the less config of yii?
Thanks for any hints, gb5256
I completely rewrote the extension to use the native JavaScript compiler. It now also supports both client and server-side compilation. Client-side compilation is great during development.
are you planning to update this extension to use the latest version of leafo's lessphp?
great extension. unfortunately it is very cpu consuming. someone asked why not compile less files only when original files are changed.. that would make an even greater extension for Yii. thanks for your work.
Hi!
Great work (again)!
Just a question : would'nt it be great if we did'nt have to create those CSS files and if they were just created and published automatically as assets, using the great Yii assets functionnality?
Cheers!
Hello,
First of all: you bootstrap is fantastic. While digging deeper into that one, LESS is next.
I did everything shown above to setup LESS, but I still do not know what to do now ... or lets say: next. Do I have to create the file css/styles.css? Where do I need to create that (inside the css folder, inside the less folder).
To point at the official documentation of LESS is not so useful, as I do not know what your extension exactly does and how it incoporates the official LESS within Yii.
Or are there too many trees in front of my eyes so that I do not see the forrest?
gb5256
and doesn't seem to work with import statements
try this less compiler for bootstrap
Leave a comment
Please login to leave your comment.