Yii Framework Forum: register conditional javascript (<!--[if) - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

register conditional javascript (<!--[if) Rate Topic: -----

#1 User is offline   mbetel 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 26-February 09
  • Location:Netherlands

Posted 04 May 2010 - 07:21 AM

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?

Thanks,

Michiel
Michiel Betel
0

#2 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,016
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 04 May 2010 - 07:34 AM

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!
-1

#3 User is offline   mbetel 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 26-February 09
  • Location:Netherlands

Posted 04 May 2010 - 07:38 AM

View PostMike, on 04 May 2010 - 07:34 AM, said:

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 :)
Michiel Betel
-1

#4 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,016
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 04 May 2010 - 07:44 AM

Add these:
http://www.yiiframew...oc/cookbook/31/

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" />
...


-1

#5 User is offline   juniorplenty 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 30-January 10

Posted 01 June 2010 - 03:50 PM

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


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

<!--[if IE 8]>
<link rel="stylesheet" type="text/css" href="<?php echo $map['byt-screen-ie8-css'] ?>" />
<link rel="stylesheet" type="text/css" href="<?php echo $map['byt-misc-ie8-css'] ?>" />
<![endif]-->


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.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users