List Info

Thread: nested wrappers and variables




nested wrappers and variables
user name
2006-06-07 22:25:53
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.frazieralumni.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-admintemplate-toolkit.org
> [mailto:templates-admintemplate-toolkit.org] On
Behalf Of Dustin Frazier
> Sent: Wednesday, June 7, 2006 1:28 PM
> To: templatestemplate-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
> templatestemplate-toolkit.org
> http://lists.template-toolkit.org/mailman/listinfo/t
emplates
>
>
>
> _______________________________________________
> templates mailing list
> templatestemplate-toolkit.org
> http://lists.template-toolkit.org/mailman/listinfo/t
emplates
>

_______________________________________________
templates mailing list
templatestemplate-toolkit.org
http://lists.template-toolkit.org/mailman/listinfo/t
emplates
nested wrappers and variables
user name
2006-06-08 04:01:55
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:ceeshekgmail.com] 
Sent: Wednesday, June 7, 2006 3:26 PM
To: Dustin Frazier
Cc: templatestemplate-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.frazieralumni.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-admintemplate-toolkit.org
> [mailto:templates-admintemplate-toolkit.org] On
Behalf Of Dustin 
> Frazier
> Sent: Wednesday, June 7, 2006 1:28 PM
> To: templatestemplate-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
> templatestemplate-toolkit.org
> http://lists.template-toolkit.org/mailman/listinfo/t
emplates
>
>
>
> _______________________________________________
> templates mailing list
> templatestemplate-toolkit.org
> http://lists.template-toolkit.org/mailman/listinfo/t
emplates
>


_______________________________________________
templates mailing list
templatestemplate-toolkit.org
http://lists.template-toolkit.org/mailman/listinfo/t
emplates
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )