Yii Framework Forum: Include Javascript And Css - Yii Framework Forum

Jump to content

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

Include Javascript And Css Include Javascript and CSS Rate Topic: -----

#1 User is offline   Nisanth thulasi 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 62
  • Joined: 10-July 12
  • Location:Kochi

Posted 04 October 2013 - 08:01 AM

Including Javascript And Css
 $baseUrl = Yii::app()->baseUrl; 
  $cs = Yii::app()->getClientScript();
  $cs->registerScriptFile($baseUrl.'/js/yourscript.js');
  $cs->registerCssFile($baseUrl.'/css/yourcss.css');

Thanks
Nisanth Thulasi
0

#2 User is offline   Shahcheraghean 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 478
  • Joined: 12-December 12
  • Location:Mashhad, IRAN

Posted 04 October 2013 - 08:28 AM

Thank you.
How to include the css files in header and the .js files in footer of the site?
www.shgn.ir
www.shgn.ir/yii-framework/
yii2.swsco.ir
In a world without any fences or walls,Who needs Gates or Windows!
0

#3 User is offline   yugene 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 504
  • Joined: 08-August 09

Posted 05 October 2013 - 03:17 AM

View PostShahcheraghean, on 04 October 2013 - 08:28 AM, said:

How to include the css files in header and the .js files in footer of the site?

Styles will be registered a head tag.
To place js at desired position you need to pass second parameter of registerScriptFile() method
Example:
$cs->registerScriptFile($baseUrl.'/js/yourscript.js', CClientScript::POS_END);


There's a convenient practice also to configure default scripts position this way (put it to 'components' section of your config file):

'clientScript' => array(
	'class' => 'CClientScript',
    'coreScriptPosition' => CClientScript::POS_END,
    'defaultScriptFilePosition' => CClientScript::POS_END,
    'defaultScriptPosition' => CClientScript::POS_READY,
),


2

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