Javascript In View Not Registered While Renderpartial

I need to build an iFrame content with Yii, so I decided to use "renderPartial" method to skip default layout header.

This is my view file’s HEAD section:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <meta name="language" content="en" />


    <title>My iFrame</title>


    <?php

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

    $cs->registerCoreScript('jquery');

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

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

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

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

    $cs->registerCssFile(Yii::app()->baseUrl . '/css/main.css');

    $cs->registerCssFile(Yii::app()->baseUrl . '/css/form.css');

    ?>


    <!-- blueprint CSS framework -->

    <link rel="stylesheet" type="text/css" href="/css/screen.css" media="screen, projection" />

    <link rel="stylesheet" type="text/css" href="/css/print.css" media="print" />

    <!--[if lt IE 8]>

    <link rel="stylesheet" type="text/css" href="/css/ie.css" media="screen, projection" />

    <![endif]-->


</head>

Unfortunately, for whatever reason none of the Javascript/CSS files is registered!

Page source sshows nothing linked!!!

But as soon as I do a test and render full rather than partial - all files are properly registered. But I need partial render not full!

Any idea???

Hi Ziggi,

If you look at the API: CController::renderPartial, you’ll notice that the fourth parameter is $processOutput, this defaults to false. Process output tells Controller/ClientScript to output the script and link tags that correspond to the registered script files/css.

Bingo !!!

Big thanks!

I’ve got the same problem, so I didn’t start a new topic.

CODE

In my controller:


$this->renderPartial('create',array(

    'model'=>$model,

),true,true);

In my create:


<?php echo $this->renderPartial('_form', array(

    'model'=>$model

), true, true); ?>

In my _form:


$this->widget('ext.CKEditor.CKEditor',array(

     "model"=>$model,

     "attribute"=>'value',

     "editorID"=>$editorID,

 ));

and lastly in my widget:


/** @var $cs CClientScript */

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

$cs->registerScript('CKEditor-replace', 'CKEDITOR.replace(\''.$this->editorID.'\', {customConfig: \'config_educate.js\'});', CClientScript::POS_END);

As you can see, I’ve set in all my renderPartials $return AND $processOutput to true.

I seem to be stuck.

Dear Friend

If I am not wrong it is meant thatif third parameter is true ,it is rendering the view but it is not echoing the view.

so it should be




echo $this->renderPartial('create',array(

    'model'=>$model,

),true,true);



or




$this->renderPartial('create',array(

    'model'=>$model,

),false,true);



Regards.

Thank you for your answer, but it didn’t work.

In my widget, it still doesn’t register my scripts.

Neither does it when $return is true, and $processOutput is false.

Dear Friend

I am sorry about that.

Have you checked the things in firebug? is there any related javscript rendered?

Is there any errors at console?

Then you have got two varable in the view.




$editorID



and




$this->editorID



Do they denote same thing or defined differently.

Would you please try the following code?




$cs->registerScript('CKEditor-replace', 'CKEDITOR.replace("'.$editorID.'", {customConfig: "config_educate.js"});', CClientScript::POS_END);



or




$cs->registerScript('CKEditor-replace', 'CKEDITOR.replace("'.$editorID.'", {customConfig: "config_educate.js"});', CClientScript::POS_BEGIN);



Regards.

I had indeed some major javascript errors that weren’t caught.

So my problem was not one of Yii. Thank you very much for guiding me to a solution.

Dear pjetr,

The third parameter ($return) needs to be false and the fourth Parameter ($processOutput) needs to be set true.

$this->renderPartial(‘create’,array(

'model'=&gt;&#036;model,

),false,true);

So what seenivasan said on Post #5 should work.