Render View In Another View (Including Js)

Hello!

I have a two views for create and update users on my site (usual situation), and both views share other view, called "_form.php", which holds CActiveForm widget.

Also I want to add functionality to form, using jsTree plugin, and I want it on both views, create and update. So, I put this code in _form.php…




$cs = Yii::app()->getClientScript();


$cs->registerCoreScript('jquery');


$cs->registerScriptFile(Yii::app()->baseUrl . "/js/jquery.jstree.js");

$cs->registerScript('helpers', '

	Yii = {

            customerRoleId : ' . User::CUSTOMER_ID . ',

	    fetchTreeUrl : ' . CJavaScript::encode(CHtml::normalizeUrl(array('contractor/index'))) . ',

	    userLogin: ' . CJavaScript::encode($model->login) . '

	};	

', CClientScript::POS_BEGIN);

$cs->registerScriptFile(Yii::app()->baseUrl . "/js/user.js");



…and render _form in create and update views using renderPartial() with third parameter set to ‘true’.

Unexpectedly, all my js files have been included twice, once in head section of page and once immediately before form. I guess such behavior caused by double output process, one within render(‘create’), and second in renderPartial.

I resolve this by duplicate code above in create and update views, so now it’s ok. But I wonder, is there a better practice?