how to add a conditional css link to a page?

Hello… I’m trying to dynamically add the following conditional link:

<!--[if lt IE 7]>

<link rel="stylesheet" type="text/css" href="/library/highslide/highslide-ie6.css" />


I didn’t find a way to do it using CClientScript. Any help will be appreciated…



I think this will work:

record a clip (probably in the controller)


  echo '<!--[if lt IE 7]>';

  echo '<link rel="stylesheet" type="text/css" href="/library/highslide/highslide-ie6.css" />';

  echo '<![endif]-->';


in your layout file

<?php echo $this->clips['test'] ?>


Or conditionally emit the code in place


  if (some_condition){

    echo '<!--[if lt IE 7]>';





You can use Yii::app()->request->getBrowser() to retrieve the browser information. Based on them you could register an additional clientscript by using Yii::app()->clientscript->registerCssFile()

If that ie6 specific css will be applied to every page then the best place to put it would be in your layout file, clientScript won’t add the piece of markup for targetting IE so you should echo it out and use CHtml to echo it out.

example here

echo '<!--[if lt IE 8]>'.CHtml::cssFile(Yii::app()->theme->baseUrl.'/css/ie.css','screen, projection').'<![endif]-->';

if your css doesn’t work you can try this

echo '<!--[if lt IE 8]>'.CHtml::cssFile(Yii::app()->theme->baseUrl.'/css/ie.css').'<![endif]-->';

I encountered an unexpected problem when the media property was in it.