Disabling a TT wrapper for Ajax requests
When using the TT skeleton created by Catalyst::Helper::View::TTSite it provides a "wrapper" which places a common header and footer around every view, allowing you to just have the "meat" of each view while the common HTML headers and footers are available (site-wide) in separate files.
However if you attempt to do any views which are only partial pages (e.g. an AJAX update) the wrapper will be incorrectly applied and your update will have a complete page rather than just the update contents.
Bypassing the wrapper
The default wrapper generated by the helper (root/lib/site/wrapper) contains code which looks at the filename of the template and avoids wrapping the template contents with the site/html and site/layout wrappers if the template name looks like CSS, JavaScript, or plain text.
The trick is to add a separate variable in addition to the template name check and then set that variable to true in requests which should bypass the layout.
[% IF no_wrapper or template.name.match('\.(css|js|txt)');
debug("Passing page through as text: $template.name");
content;
ELSE;
debug("Applying HTML page layout wrappers to $template.name\n");
content WRAPPER site/html + site/layout;
END;
-%]
And then call $c->stash(no_wrapper => 1); in the controller to disable the wrapper for views as needed.
Similarly you could provide TT logic to use different sets of wrappers based on a stash variable.
Showing changes from previous revision. Removed | Added

