dk4210
(Dankelly2006)
November 14, 2011, 1:32pm
1
Hello Guys,
Can some one tell me how to incorporate a custom jquery script inside of yii?
Here is the one that I want to implement (2234
vscroller.zip
attached zip file to this ticket.)
I am a newbie and I don’t understand how to include custom scripts inside of yii…
If you know of a jquery scroller with XML file reading capable abilities that will install easily in yii, please let me know…
Please advise.
Thanks, Dan
wisp
(Wisp)
November 14, 2011, 2:25pm
2
Just create a new javascript file and include it in your controller or in the <head> of the view layout
madand
(Dev Madand)
November 14, 2011, 4:21pm
3
Hi dk4210 ,
the exact solution depends on whether you need JS file included on all (or mostly all) pages of site or on just several ones:
if former - include JS file in layout file, but notice that Yii includes bundled scripts (like jQuery) right before <title>-tag, so you better place you <script>-tag(s) after <title>-tag.
if latter - then you might use CClientScript::registerScriptFile in you controller or view like this:
Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl . '/js/yourFile.js');
dk4210
(Dankelly2006)
November 14, 2011, 4:22pm
4
Ok That’s it?
Easy enough… I thought there was a specific structure with this framework…
wisp
(Wisp)
November 14, 2011, 8:52pm
5
MadAnd:
Hi dk4210 ,
the exact solution depends on whether you need JS file included on all (or mostly all) pages of site or on just several ones:
if former - include JS file in layout file, but notice that Yii includes bundled scripts (like jQuery) right before <title>-tag, so you better place you <script>-tag(s) after <title>-tag.
if latter - then you might use CClientScript::registerScriptFile in you controller or view like this:
Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl . '/js/yourFile.js');
afaik Yii does a replace on </head> and replaces it with [js files]</head> so it has nothing to do with title tag
madand
(Dev Madand)
November 15, 2011, 11:05am
6
CClientScript::renderHead:
....
if($html!=='')
{
$count=0;
$output=preg_replace('/(<title\b[^>]*>|<\\/head\s*>)/is','<###head###>$1',$output,1,$count);
if($count)
$output=str_replace('<###head###>',$html,$output);
else
$output=$html.$output;
}
....
So you can see that JS codes are being included before <title>-tag, but if no <title>-tag presented - then before </head>-tag.