On 19/6/09 06:25, Fayland Lam wrote:
> the only choice to use INCLUDE instead of WRAPPER? or we have another
> choice/option?

There isn't anything built-in that does wrappers-in-reverse, but it's fairly
easy to roll your own using the TT equivalent of callbacks.  You have your
outer wrapper callback (via INCLUDE or PROCESS) to a named BLOCK where you 
define your content.

wrapper.tt2
[%  test.push('wrapper.A');
     test.push('wrapper.B');

     PROCESS content;           # Note the extra PROCESS

     test.push('wrapper.C');
     test.push('wrapper.D');
%]

inside.tt2
[%  test = ['AA'];

     PROCESS wrapper.tt2;

     BLOCK content;
       test.push('inside.A');
       test.push('inside.B');
     END;

     test.join(', ');
%]

This generates the desired output:
   AA, wrapper.A, wrapper.B, inside.A, inside.B, wrapper.C, wrapper.D

Although there's a little more code to write, this approach has the benefit
of supporting multiple "slots" that you want filled in.  So it's ideal for
defining general layout templates, e.g. for a web site.

layout.tt2:
   <div id="layout">
     <div id="header">
       [%- PROCESS header -%]
     </div>
     <div id="sidebar">
       [%- PROCESS sidebar -%]
     </div>
     <div id="content">
       [%- PROCESS content -%]
     </div>
     <div id="footer">
       [%- PROCESS footer -%]
     </div>
   </div>

example.html:
[%  PROCESS layout.tt2 %]

[%  BLOCK header %]
       Header content
[%  END %]

[%  BLOCK sidebar %]
       Sidebar content
[%  END %]

[%  BLOCK content %]
       Main content
[%  END %]

[%  BLOCK footer %]
       Footer content
[%  END %]

Output:
   <div id="layout">
     <div id="header">
       Header content
     </div>
     <div id="sidebar">
       Sidebar content
     </div>
     <div id="content">
       Main content
     </div>
     <div id="footer">
       Footer content
     </div>
   </div>


Cheers
A



_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates

Reply via email to