Thank Andy.
I think I just wrote my question in a too-simple way. let me show you 
the real one. Sorry to waste your time.

we have a Catalyst App. and View/TT.pm and we set WRAPPER as 
'wrapper.html'. and it contains:
[% c.include('css/css1.css');
[% FOREACH css IN StaticCSS %]
[% c.include_css('css/' _ css); %]
[% END %]
[% c.include('css/css4.css'); %]
[% c.export_css; # we have some trick here. but it doesn't matter %]
[% content %]

then in another template like 'index.html'
[% StaticCSS = ['css2.css'] %]
[% c.include('css3.css'); %]

* Situation one. use WRAPPER. it shows css3.css, css1.css, css2.css, 
css4.css
* Situation two. split wrapper.html into header.html and footer.html. 
use PRE_PROCESS to do header.html.
the StaticCSS is missed since header.html is processed before we set 
StaticCSS in index.html
* your example really shows me another way to write TT2. I'll try that 
later.

I come out to use a rank like:
[% c.include_css('css/css1.css', 999) %]
put 999 in wrapper.html before [% content %]
and with more tricks. it works.

Thanks anyway. I really appreciate your instant reply.

Andy Wardley wrote:
> 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
>
>
>


-- 
Fayland Lam // http://www.fayland.org/
Foorum based on Catalyst // http://www.foorumbbs.com/


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

Reply via email to