[Templates] multiple uses of component-like template
Josh Rosenbaum
josh@infogears.com
Thu, 03 May 2007 14:30:00 -0600
Dustin Frazier wrote:
> I have a template that I use to create a two-column layout in a standard
> way. The template looks something like:
>
> <table>
> <tr>
> <td>
> [% INCLUDE left %]
> </td>
> <td>
> [% INCLUDE right %]
> </td>
> </tr>
> </table>
>
> (There's more to the real template to setup classes and styles to manage
> column width, spacing, etc., and yes I know using CSS would be better
> [for some definition of "better"]).
>
> I then use the template like so:
>
> [% WRAPPER two_columns %]
> [% BLOCK left %]
> stuff for left column
> [% END %]
> [% BLOCK right %]
> stuff for right column
> [% END %]
> [% END %]
>
> This works great until I try to use the two_columns template more than
> once on a page. When I try that, the *last* instance of the 'left' and
> 'right' block is used in each use of the wrapper template.
>
> Is there a better practice for accomplishing this kind of component-like
> behavior each with multiple content blocks?
Dustin,
Maybe something like this:
[% BLOCK left1 %]
stuff for left column
[% END %]
[% BLOCK right1 %]
stuff for right column
[% END %]
[% PROCESS two_columns left = 'left1' right='right1' %]
(Your includes would be something like: [% INCLUDE $left %]
Another way might be to do:
[% left = BLOCK %]
stuff for left column
[% END %]
[% right = BLOCK %]
stuff for right column
[% END %]
[% PROCESS two_columns %]
Then in two columns you'd do: [% left %] instead of [% INCLUDE left %]
-- Josh