renderPartial and scripts


I am not sure how the fourth parameter works.

I have a form that I render in ajax using renderPartial, but if I set the fourth parameter to true, it always breaks when I do my ajax calls.

But if I remove it, it works fine.

The scripts that break seem to be the ones in the main portion of the page and not the rendered partial ones.

What’s the best way to not have it conflict?

Would it be to just not use the fourth parameter?

I’m looking for your suggestions or experience on this.


Fourth parameter turns post-processing on/off. That’s where scripts and CSS are included. It should be an error is because something is not included properly.

The way i’m doing this is as followed:

I register CSS and scripts using CClientScript in my controller (because if I switch themes I want the scripts to still be available).

In my view page, I register additional scripts that work for that page only.

In my partialRender view page, I have additional scripts.

When I use the fourth parameter to render my partial view it breaks because of a script call which says it’s missing.

The script missing seems to be the ones including from my controller.

What would be the best method to fix something like this?

I’m still learning, thanks for your help guys!

This is still a bug of the framework.

There are no official solution for now. Take a look at this post for my workaround about this problem.

How you noticed is impossible to use the fourth parameters, because ALL the script will be replaced, including the script that you didn’t include in the render partial.

Another problem is that the ids that are authomatically generated by Yii will break after an ajaxSubmission: if you have 2 links in the main view (will be named yt0, yt1) and 2 links in the subview that will be reloaded with ajax (yt2, yt3).

When you will call renderPartial on the subview the 2 links will be named yt0, yt1 (because you are not rendering the main view once again) with the obviously consequences.

The solution I propose in my post is to write in the view to renderPartial all the clientScript required by the view itself. That solve the problem of the clientscript of the subview.

For the problem of the id there are no solution right now because the ‘ytn’ id is hardcoded in CHtml and cannot be changed. You can workaround this point by giving a unuque id to ALL object in the subview (links and so on).

In my long experience in Yii, this is the only one week point of the framework, I hope that the devTeam will take in consideration to resolve it.

Thank you for your detailed response on this issue, I had read previously your post about your work around and it is currently what i am doing also, I just wasn’t sure if the way I was doing it was correct or not, thanks again! :D