Revision #2 has been created by trond on Feb 11, 2014, 8:51:56 PM with the memo:
Improved the explanation of the problem
« previous (#1) next (#3) »
Changes
Title
unchanged
How to apply a layout to an AJAX update
Category
unchanged
How-tos
Yii version
unchanged
Tags
unchanged
AJAX, views
Content
changed
[...]
2. One or more layout files holds the column setup, sub navigation etc.
3. The view files hold the actual page content.
When you load a page, the render method does the following:
1. Renders the view file.
2. Decorates the view with the layout
.
3. Apply the template to the layout.
An AJAX call is normally much more lightweight
(and much faster). If you use _renderPartial_ with the _processOutput_ parameter set to false,
neither the layout
andnor the template is never added to the output.
All you get is the content produced by the view file.
The problem
-----------
Sometimes, however, it can be useful to also switch the layout on an AJAX update, without having to load the whole page with
all CSS, JS etcthe full overhead of CSS files, javascript, fonts etc. So what we need is a way to render the view file and have it embedded in the layout without also getting the template file applied. That is still much faster than loading the full page.
The solution
------------
The following code snippet from a controller action specifies the view to be rendered and the layout to be applied. For an AJAX update, a _renderPartial_ is used to generate and return the view file. Then a _CContentDecorator_ is created to apply the layout.[...]