Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Template Toolkit, problem with recursive wrapper templates

by larsen (Parson)
on Jul 11, 2005 at 21:43 UTC ( #474106=perlquestion: print w/ replies, xml ) Need Help??
larsen has asked for the wisdom of the Perl Monks concerning the following question:

I have a problem with Template Toolkit, more specifically with the WRAPPER directive. I'm using ttree. In my ttreerc I defined a wrapper, let's call it "foo". Then, in one of the pages, I used a redirect() FILTER to produce several pages, each described in a data structure defined in the page. This is very similar to my actual code:
[% categories = [ ... ] %] [% FOREACH c IN categories %] [% FILTER redirect( $c ) %] bla bla bla [% END %] [% END %]
Now, I'd like each category page to use the same wrapper. My first attempt has been the following:
... [% FILTER redirect( $c ) %] [% WRAPPER foo %] bla bla bla [% END %] [% END %] ...
but it does not work, leading to ! file error - recursion into 'wrapper.tt2' in the build phase. Allowing recursion via ttree config leads just to deeper errors.
I think I'm facing a common problem, which I'm trying to solve using the wrong tecnique. What's your advice ? Thank you.

Comment on Template Toolkit, problem with recursive wrapper templates
Select or Download Code
Re: Template Toolkit, problem with recursive wrapper templates
by waswas-fng (Curate) on Jul 11, 2005 at 22:44 UTC
    What does your Template->new look like? Do you Process => wrapper.tt2 or Wrapper => wrapper.tt2?


    -Waswas
      I'm not using Template directly, but via ttree. It's WRAPPER => 'wrapper.tt2', though, since I'm using wrapper = wrapper.tt2 in the ttree config file.
Re: Template Toolkit, problem with recursive wrapper templates
by waswas-fng (Curate) on Jul 11, 2005 at 22:44 UTC
    oops double post..


    -Waswas
Re: Template Toolkit, problem with recursive wrapper templates
by Your Mother (Canon) on Jul 11, 2005 at 23:32 UTC

    I hope this isn't a dumb answer but do you have the 'RECURSION' flag on in your config? It's off by default.

      Yes I tried, and it causes deep recursion error during the build phase. Actually, I haven't tried that option with every variation of code I was conjuring with.
Re: Template Toolkit, problem with recursive wrapper templates
by mugwumpjism (Hermit) on Jul 12, 2005 at 05:48 UTC

    That's a real bummer. Especially since WRAPPER classes are by their nature likely to be used more than once in a single call stack.

    If I were you, I'd consider hacking the Template Toolkit modules themselves so that they don't do this check for WRAPPER directives, and sending a patch to the TT list for discussion.

    $h=$ENV{HOME};my@q=split/\n\n/,`cat $h/.quotes`;$s="$h/." ."signature";$t=`cat $s`;print$t,"\n",$q[rand($#q)],"\n";
Re: Template Toolkit, problem with recursive wrapper templates
by larsen (Parson) on Jul 12, 2005 at 12:46 UTC
    I think I figured out how to solve the problem. I changed wrapper.tt2 this way (applying this advice):
    [% IF template.naked; content; ELSE; content WRAPPER site_wrapper.tt2; END; %]
    Then, in my template:
    [% META naked = 1 %] [% WRAPPER site_wrapper.tt2 %] + whatever [% END %] [% FOREACH c IN categories %] [% FILTER redirect("${c.name}/index.html") %] [% PROCESS portfolio/category %] [% END %] [% END %]
    site_wrapper.tt2, as you can guess, contains the code that was in wrapper.tt2. In portfolio/category:
    [% WRAPPER site_wrapper.tt2 %] it works! [% END %]
    Now I have another problem: changing META informations in the processed template. But that's another issue.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://474106]
Approved by kvale
Front-paged by friedo
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (14)
As of 2014-07-30 14:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (234 votes), past polls