Personal tools
Plone of these days

Plone, I'm going to cut you in to little pieces

Jul 03, 2012

Plone of these days

We start from the typical use case of making a Plone page fit inside an iframe, than we'll see the many ways Plone page rendering process can be controlled by properly setting request parameters

Did you ever wanted...

... to just include the main content from a Plone page in an iframe and for this reason struggled with customized views and CSS rules to remove unwanted page elements like portlets, viewlets, footer and so on?

Did you know...

... that there is a simple and easy way to request Plone to serve a page with only the main content, skipping all the surrounding elements for navigation?

For the impatients

To embed a page inside an iframe, since Plone 4.0.3,  you have the option to include just the main content by appending the query string: ?ajax_load=1&ajax_include_head=1, to the URL inside the src attribute.



As an example, with this test HTML:
<h1>Boxing Plone</h1>
<iframe width="480" height="200"
<iframe width="480" height="260"



You end up with something like this:

The page displays the login form and the sitemap without all the elements that are not relevant for this use case (logo, headers, footer, portlets, viewlets and so on).


Be aware that customizing the style in the "iframed" HTML is possible using some javascript techniques (see for example this question on stackoverflow) and that if you include HTML from a different domain you may have to struggle with the Same Origin Policy.

If you use a customized main template that is not aware of this technique you could have different results!

tl;dr AKA Toooo Long: Don't Read AKA Hic Sunt Leones

The parts of the page that "disappear", when request parameters are properly set, are not rendered at all by the server because the default main_template is "request aware". Looking at it (see sunburst on github) it is possible to understand in detail what is happening.

The ajax_load parameter, if set to a non null value, disables the rendering of many sections of the template (e.g. portal_top, viewlets and the portlet columns).

The ajax_include_head forces the plone.head provider to be rendered even if the ajax_load parameter would remove it from the page.

If ajax_load is set and ajax_include_head is not, you will end up with and unstyled HTML page that will also miss the javascript. This behaviour turns out to be handy when making javascript overlays: in this case the styles and javascripts are taken from the page that will start the ajax call.

Since Plone 4, there is also the chance to disable portlet columns by adding the request parameter ?disable_$NAME=1, where $NAME is the portlet manager (e.g. plone.leftcolumn or plone.rightcolumn). So the url to disable both the left and right column will be something like this:

On github you can find the relevant code: take a look to the have_portlets method.

In many ZPT templates those request parameters are enforced using dummy defines:

disable_column_one python:request.set('disable_plone.leftcolumn',1);
disable_column_two python:request.set('disable_plone.rightcolumn',1);

Take a look (e.g.) to the dashboard page template.

The capability of Plone to disable template parts by request is not a prerogative of Plone 4. For example, for years now, setting the parameter ?disable_border=1, it is possible to remove the "green bar" on top of the views (the one that appears when you are logged in and let's you add/modify contents and make some more actions).

Do you know...

... any other trick like those?

Filed under: , , , ,
comments powered by Disqus