[Templates] object-oriented templates, inheritance, references to blocks : HOWT O ?
[prev]
[thread]
[next]
[Date index for 2004/04/27]
Hi everybody,
First of all, thanks to the TT2 designers for this wonderful framework.
I have a collection of templates which is likely to grow, and where=20
some components are shared, but the problem is that reuse is=20
context-dependent : in some cases a standard component can be
directly grabbed from the library ; in some cases it needs=20
a couple of local redesign adjustments.
It seems that plain inclusion of block components does not fit here,
so I'm trying to design the template collection in an object-oriented
way. The goal would be to be able to "subclass" a template and
overload some of its components. Something along the following line :
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
file base.tt
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
[% BLOCK part1 %]
this is part1 in base.tt
[% END %]
[% BLOCK part2 %]
this is part2 in base.tt
[% END %]
[% BLOCK part3 %]
this is part3 in base.tt
[% END %]
[% BLOCK main;
PROCESS part1 + part2 + part3;
END %]
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
file subclass.tt
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
[% PROCESS base.tt %]
[% BLOCK part2 %]
this is part2 overloaded in subclass.tt
[% END %]
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
file main.tt
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
[% PROCESS subclass.tt %]
[% main %]
Now I have two problems :
1) currently the result is not as expected : output of part2 is still
"this is part2 in base.tt". This is because there is early binding
in base.tt from block "main" to block "part2". I tried various
ways to achieve late binding, using MACRO or using variables=20
(i.e [% p2 =3D "part2"; PROCESS "$p2" %]) but still no success.
Anybody has a clue ?
2) assuming problem 1) is solved, the other problem is to call
"super". Let's say that block "part2" in subclass.tt wants
to invoke "part2" in base.tt. How can that be done ?
I guess what I'm asking here is how to take a _reference_ to a block
and put that in a variable. Possible ?
Thanks in avance for any help,=20
Laurent Dami
Conseiller en syst=E8mes d'information
Palais de Justice - Etat de Gen=E8ve
Case postale 3966
Place du Bourg-de-Four 3, 1211 Gen=E8ve 3
+41 (22) 327 20 64 (direct), +41 (22) 327 20 37 (service)
http://cui.unige.ch/~dami
_______________________________________________
templates mailing list
templates@xxxxxxxxxxxxxxxx.xxx
http://lists.template-toolkit.org/mailman/listinfo/templates
 |
[Templates] object-oriented templates, inheritance, references to blocks : HOWT O ?
Dami Laurent (PJ) 16:21 on 27 Apr 2004
|