防止将特定的CSS文件加载到Yii中 [英] Preventing a specific CSS file from getting loaded in Yii
问题描述
我在Yii中编码。
我已经在main.php布局文件中注册了main.css文件,如下所示:
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.
我知道使用:
Yii::app()->clientScript->reset();
将删除所有CSS文件,但是我只希望注销少数CSS文件。
would remove all the CSS files, however I want only few CSS files to be unregistered.
有办法吗?
推荐答案
您可以使用< CClientScript的
在您的特定视图中,为您不想渲染的特定脚本/ css文件的密钥传递 scriptMap
属性 false
。在文档中:
You can use the scriptMap
property of CClientScript
in your specific view, passing false
for the particular script/css file's key that you don't want to be rendered. From the doc:
数组键是脚本文件名(不带目录部分),数组值是相应的URL。如果数组值为false,则不会呈现相应的脚本文件。
The array keys are script file names (without directory part) and the array values are the corresponding URLs. If an array value is false, the corresponding script file will not be rendered.
例如,在说 views / site /pages/about.php:
Yii::app()->clientScript->scriptMap = array(
'main.css' => false
);
禁止包含在<$ c $中注册的 main.css c> registerCssFile 。
to disable the inclusion of main.css registered with registerCssFile
.
scriptMap
也可以用于控制js脚本文件。
The scriptMap
can also be used for controlling the rendering of js script files.
这篇关于防止将特定的CSS文件加载到Yii中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!