With this extension, you can use Less CSS files with registerCSSFile.
The code is based on zsoltlengyelits, LessCSS-for-Yii extension. I've updated it so,
Yii 1.1 or above
Copy the folder to your extension folder (protected/extensions).
Extend CClientscript:
'components' => array( 'clientScript' => array( 'class' => 'ext.LessClientscript.LClientscript', 'caching' => true, //use the cached css file if available 'compress' => false, //remove whitespace and linearize to 1 line ) );
Done!
Now you can add it in your view or controller:
Yii::app()->clientScript->registerCSSFile('src/app/admin/stylesheets/test.less');
V1.02 - Store temporary less file in runtime folder - Fixed bug where if you provided a file with no css in it, it could not find the assets file
V1.01 - Better commenting - Return clientscript object for chaining - Refactoring
Total 6 comments
According to Yii documentation (http://www.yiiframework.com/doc/guide/1.1/en/topics.theming)
The theme directory should point out to Webroot/themes (or in other words: Yii::getPathOfAlias('webroot') . DIRECTORY_SEPARATOR . 'themes')
So it's weird there's overlap. Could you try
That does not correct it...
I think the problem is the following:
gives me /my/web/themes/mytheme/less/ta.less
but
gives me /srv/http/nginx/html/my/web/
so the paths overlap a bit...
Hi,
Sorry I don't have a nginx server to test this. Could you try something for me?
In LClientscript.php change the
to
LClientscript: Less stylesheet not found: /srv/http/nginx/html/my/web//my/web/themes/theme/less/ta.less
Do you see the double slash?, Am I doing something wrong?: (Its working if i specify a css file)
<?php Yii::app()->clientScript->registerCssFile(Yii::app()->theme->baseUrl.'/less/ta.less'); ?>@kmindi Hi sorry to hear that. I ran some tests, but it works fine here:
Make sure your theme folder exists (/themes/classic)
And your config is correct:
My file structure is like this:
I think some urls are not correctly parsed, for example: <?php Yii::app()->clientScript->registerCssFile(Yii::app()->theme->baseUrl.'/css/bootstrap.min.css'); ?>
Leave a comment
Please login to leave your comment.