Managing page regions
A page region is basically a part of a page that has some logic and an optical representation of its own. The html-part of a page region is represented by a mason fragment. The region may get updated by AJAX (on JavaScript capable browsers) or via query parameters.
A region can get constructed using the Jifty->web->region() method call. The freshly constructed region is rendered at the current position in the generated HTML output. The following parameters may be used:
namegives the region a name. Internally a unique id is generated. The name should only consist of letters and numbers.pathtells the renderer where to find the mason fragment.defaultscan be added to set some parameter defaults as simple scalars. Parameters named here are accessible by defining an<ARGS>section in the fragment called. As a coding convention, all fragments that act as Pageregions reside under the/fragmentsURI.
More parameters, but rarely needed:
parentspecifies the region this one is enclosed in. Normally this parameter will not be necessary as during the page rendering process, the hierarchy of regions is known.region_wrapperthis boolean value whose default value is true controls some JavaScript to get included in order to make JavaScript aware of the region's existence.
Examples
Inside any template, you could define some area that is intended for a later exchange against some other content (assuming that $id is the ID of the database record).
<% Jifty->web->region(name => "content$id",
path => '/fragments/show_Content',
defaults => { id=>$id, },
) %>
Inside the fragment, residing in /fragments/show_Content you could add a button to do the swapping:
<% Jifty->web->link(
label=>'edit',
onclick=>{
replace_with => '/fragments/edit_element',
args => { id=>$id },
},
) %>
And finally, in the edit fragment /fragments/edit_element a switch back looks similar like the one above.
Keep in mind, that calls like the ones above will only successfully work, if all called region fragments will have a <ARGS> section defining the $id parameter.