[Templates] nested wrappers and variables
Dustin Frazier
dustin.frazier@alumni.cmu.edu
Wed, 7 Jun 2006 21:01:55 -0700
I'm using ttree to build my site. Can anyone confirm that the $template
variable would be setup before the pre-processing happens for each template?
I'm still curious why my original usage of variables and wrappers doesn't
work...
Dustin
-----Original Message-----
From: Cees Hek [mailto:ceeshek@gmail.com]
Sent: Wednesday, June 7, 2006 3:26 PM
To: Dustin Frazier
Cc: templates@template-toolkit.org
Subject: Re: [Templates] nested wrappers and variables
If this needs to occur in every single template, then it may be easier to
just use the PRE_PROCESS directive when creating your Template Toolkit
object:
my $template = Template->new( PRE_PROCESS => 'base.tmpl' );
Anything you declare in the PRE_PROCESS will be visible in all of your
templates.
Cheers,
Cees
On 6/7/06, Dustin Frazier <dustin.frazier@alumni.cmu.edu> wrote:
> I managed to get this to work by using INCLUDE and BLOCK rather than
> WRAPPER:
>
> base:
> [% IF template.name.match('/') -%]
> [%- DEFAULT section = template.name.replace('/.*','') -%] [% END -%]
> <html> <body> [% INCLUDE contents %] ...
>
> page:
> [% INCLUDE base %]
> [% BLOCK contents %]
> <h1>Section: [% section %]</h1>
> [% INCLUDE content %]
> [% END -%]
> ...
>
> foo.tt2:
> [% INCLUDE page -%]
> [% BLOCK content -%]
> My content here...
> [% END -%]
>
> It works, but it seems pretty convoluted to me, and I have to use
> different block names for the different levels of inclusion.
>
> Is my brain completely inside out on this one, or is there some clear
> explanation for why variables set in a wrapper aren't available to the
> template that uses the wrapper?
>
> Thanks!
>
> Dustin
>
> -----Original Message-----
> From: templates-admin@template-toolkit.org
> [mailto:templates-admin@template-toolkit.org] On Behalf Of Dustin
> Frazier
> Sent: Wednesday, June 7, 2006 1:28 PM
> To: templates@template-toolkit.org
> Subject: [Templates] nested wrappers and variables
>
> I have a common page template for all pages that starts like this:
>
> base:
> [% IF template.name.match('/') -%]
> [%- DEFAULT section = template.name.replace('/.*','') -%] [% END -%] ...
>
> I then have a second, more specific template that is based on this one:
>
> page:
> [% WRAPPER base %]
> ...
>
> If I try to reference the variable 'section' within a page that uses
> the 'page' wrapper, it's not defined. Is there something special I
> need to do from one wrapper template or the other to make this work?
> I don't want to duplicate all of the stuff at the top of my base
> template within the page template (code sharing being the whole point
> of having one based on the other).
>
> Thanks!
>
> Dustin
>
>
>
> _______________________________________________
> templates mailing list
> templates@template-toolkit.org
> http://lists.template-toolkit.org/mailman/listinfo/templates
>
>
>
> _______________________________________________
> templates mailing list
> templates@template-toolkit.org
> http://lists.template-toolkit.org/mailman/listinfo/templates
>