* Stefan [2011-08-10 21:05]:
What is the best practice to load a template like the following:
<html>
<body>
<div class"left">
[% content %]
</div>
<div class"right">
[% right_content %]
</div>
</body>
</html>
,content' should be replaced with left_content.tt2
,right_content' with right_content.tt2
If I use a Wrapper, only content is automatically replaced. How
can I also replace right_content?
If you want to make `right_content` dependent on the page, i.e.
you want to define both a main content and some sidebar content
*per page*, then you can keep them both in the same template
using the following structure:
First off you need two infrastructure templates in your TT
configuration:
PREPROCESS => [ 'includes.tt' ],
WARPPER => [ 'layout.tt' ],
Then in `includes.tt`:
[% BLOCK sidebar ; END %]
(Yes, an empty block. It?s there to establish a fallback so you
can leave it out later.)
Then you use it in `layout.tt`:
<html>
<body>
<div class"left">
[% content %]
</div>
<div class"right">
[% INCLUDE sidebar %]
</div>
</body>
</html>
And now in your `somepage.tt` you can write:
blah blah blah blah
[% BLOCK sidebar %]hello world[% END %]
The `sidebar` block in this template will override the one
defined in `includes.tt`, and the resulting output will be:
<html>
<body>
<div class"left">
blah blah blah blah
</div>
<div class"right">
hello world
</div>
</body>
</html>
This way you can keep all the per-page content in one template
file, but you can break it down into smaller pieces of content
that the wrapper template can layout freely.
--
*AUTOLOAD=*_;sub _{s/::([^:]*)$/print$1,(",$\/"," ")[defined wantarray]/e;chop;$_}
&Just->another->Perl->hack;
#Aristotle Pagaltzis // <
http://plasmasturm.org/>