yiisoft / yii

Yii PHP Framework 1.1.x
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
4.85k stars 2.28k forks source link

Custom stylesheet attributes in CHtml::cssFile() and CClientSript::registerCssFile() #1630

Closed velosipedist closed 12 years ago

velosipedist commented 12 years ago

CClientSript::registerCssFile() can only register 'text/css' files cause of CHtml::cssFile() can only register hardcoded 'text/css' type. Also there is no possibility to change or add any other attributes. This is not good:

return '<link rel="stylesheet" type="text/css" href="'.self::encode($url).'"'.$media.' />';

DRY CHtml::tag() feature is ignored. Is there any reason for outputting plain HTML tag that way?

Meanwhile, we cannot use non-css stylesheets (for example, .less) in packages or just with CClientSript::registerCssFile().

My proposal is to change CHtml::cssFile() signature to following:

public static function cssFile($url,$attributes='') {
// next we checking is $attributes string or array.
// First case is media attribute for BC, second - HTML tag attributes
// ...
}
creocoder commented 12 years ago

Use CClientSript::registerLinkTag() / CHtml::linkTag() instead. CHtml::cssFile() should register only css stylesheets.

velosipedist commented 12 years ago

It won't allow to include .less sources to packages and keep styles dependencies, add .less assets. I'm already writing CClientScript & CHtml solution in my own issue branch.

samdark commented 12 years ago

CHtml::cssFile() or CClientSript::registerCssFile() should not be changed because method name clearly states that it works with CSS only.