11

Is there a way to disabling a WRAPPER that was set in new(\%config), through either the template, or a temporary override with parse()? I want to have a single default WRAPPER (that I'll use for 99.9% of my templates), but exclude a few.

I'm doing this all through Catalyst::View::TT just like the example in the configuration synopsis, except I don't want the WRAPPER to apply to all of my templates.

brian d foy
  • 129,424
  • 31
  • 207
  • 592
Evan Carroll
  • 78,363
  • 46
  • 261
  • 468

3 Answers3

8

Edit the wrapper, to include a conditional like:

[% IF no_wrapper OR template.no_wrapper %] [% content %] [% ELSE %]
  top;
    [% content %]
  bottom;
[% END %]

This allows me to disable the wrapper either (1) inside of template, or (2) from the stash.

  1. [%- META no_wrapper = 1 -%]
  2. $c->stash->{no_wrapper} = 1

META var ...; is a directive that makes var accessible through the template hash as template.var

source: http://wiki.catalystframework.org/wiki/gettingstarted/howtos/template_wrappers

Evan Carroll
  • 78,363
  • 46
  • 261
  • 468
Martin
  • 96
  • 1
  • 1
    Here is the boiler plate XHTML 1.1 wrapper using this method: http://github.com/EvanCarroll/Craiglickr/blob/master/root/wrapper.tt – Evan Carroll Mar 03 '10 at 16:53
4

Define exceptions in site/wrapper itself, and btw there are exceptions defined there already.

[% IF 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;
-%]
codeholic
  • 5,680
  • 3
  • 23
  • 43
0

I stumbled into the same problem, and created a more generalized solution that allows for dynamic switching of layouts, or to have no layout at all. See here:

More than one layout/wrapper with Dancer and Template::Toolkit

Community
  • 1
  • 1
yahermann
  • 1,539
  • 1
  • 12
  • 33