I am coding in Yii.
I have registered the main.css file in my main.php layout file like so :
Yii::app()->clientScript->registerCssFile($this->assetsBase.'/css/main.css');
Now this script is being registered in all the pages. However, say I don't want that script to be registered on a specific page.
I know that using :
Yii::app()->clientScript->reset();
would remove all the CSS files, however I want only few CSS files to be unregistered.
Is there a way to do it?
You can use the
scriptMap
property ofCClientScript
in your specific view, passingfalse
for the particular script/css file's key that you don't want to be rendered. From the doc:For example, in say views/site/pages/about.php:
to disable the inclusion of main.css registered with
registerCssFile
.The
scriptMap
can also be used for controlling the rendering of js script files.I would suggest either:
Using a separate layout for that page like
main_no-css.php
or
Adding a condition before registering the script (like if controller != xxx and action != yyy), but this would cause the condition to be checked on every other page.
I would definitely go for a separate layout.