Yii Framework Forum: [Ask] Best Practice To Include Javascript Files Inside A Theme - Yii Framework Forum

Jump to content

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

[Ask] Best Practice To Include Javascript Files Inside A Theme Rate Topic: -----

#1 User is offline   sangprabo 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 03-July 12

Posted 26 February 2013 - 03:44 AM

Hi, everyone.

I'm new to Yii. I have a question regarding the way of loading a javascript file inside my view. For some reasons, I can not use the default jquery-ui or jquery script from Yii. So I come up with these lines inside my themes/awesome_theme/layouts/main.php

...
	<script src="<?php echo Yii::app()->theme->baseUrl; ?>/js/jquery.min.js"></script>
	<script src="<?php echo Yii::app()->theme->baseUrl; ?>/js/jquery.ui.custom.js"></script>
	<script src="<?php echo Yii::app()->theme->baseUrl; ?>/js/bootstrap.min.js"></script>
</body>
</html>


I want to include another javascript file to my view, for example from themes/awesome_theme/js/my_script.js, this way..

<?php Yii::app()->clientScript->registerScriptFile(Yii::app()->theme->baseUrl . '/js/my_script.js',CClientScript::POS_END);?>


The script is running well, except I can not include another PHP tag inside my .js code. If I want to include some PHP scripts, I need to include it inside a view. I'm wondering what is the best practice/way to do it. I can move the
<script src=""></script>
inside my
<head></head>
to solve this, but it will make the page load slower.

Is there any other solution to this? Thank you and please forgive my English.
0

#2 User is offline   tri 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,651
  • Joined: 20-November 08
  • Location:Stockholm, Sweden

Posted 26 February 2013 - 03:41 PM

/* Moved to General Discussion */
(not a tip, snippet or tutorial)
Don't forget to read The Definitive Guide to Yii (en) (sv) | The class reference has the details
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