register conditional javascript (<!--[if)

I’m looking for an easy way to put somthing like the following in my <head> section:

    <!--[if IE]><script language="javascript" type="text/javascript" src="excanvas.min.js"></script><![endif]-->

But CClientScript won’t let me. Anyone who knows a trick?



Why don’t you add it manually to HTML source in the view? Don’t overuse CClientScript for cases where you don’t need it!

Yes I can do that, but that means hardcoding the path to the js file, which is part of a set of js-files in an extension. Would be nice to have them in the same assets directory if only for the sake of neatness :)

Add these:


Then you can do this everywhere:

<script type="text/javascript" src="<?php echo bu('js/MyScript.js'); ?>"></script>

<img src="<?php echo bu('img/myImage.gif'); ?>" />

<link rel="stylesheet" href="<?php echo bu('css/local.css') ?>" type="text/css" />


I’ve used this technique, it’s kind of a hack:

<?php $map = Yii::app()->clientScript->scriptMap; ?>

<!–[if IE 8]>

&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;&lt;?php echo &#036;map['byt-screen-ie8-css'] ?&gt;&quot; /&gt;

&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;&lt;?php echo &#036;map['byt-misc-ie8-css'] ?&gt;&quot;   /&gt;


This is a useful feature, guys - I use different versions of CSS files between dev and stage/live (I combine and minify them,) so the scriptMap feature is great - I just map to different locales per environment. Hardcoding these links breaks that kind of model, I’m sure there are other examples.