Hi everybody,
Some considerations about the VIEW design.
A couple of months ago I asked about object-orientation and
inheritance in TT. Randal Schwarz pointed me to the VIEW construct
which can take a "base" parameter and therefore brings inheritance.
This works fine : methods can call other methods and properly find
the right implementation. However, when it comes to calling "super",
there seems to be a flaw : the late binding to "self" (the current
view) is lost. This is shown in code below, in the view v3.
I found a fix in view v4 : bind again the view to itself (view=view)
and it works fine. However, it seems to me that somehow this should
be part of the VIEW design.
Any opinions ?
Regards,
Laurent Dami
Etat de Gen�ve, Pouvoir Judiciaire
[EMAIL PROTECTED]
===================================================================
[%- VIEW root;
view.name = "root";
BLOCK whoami; "My name is " _ view.name; END;
END; -%]
[%- VIEW v1 base=root; view.name = "v1"; END; -%]
[%- VIEW v2 base=root;
view.name = "v2";
BLOCK presentMe; view.whoami() _ " and I live in v2"; END;
END; -%]
[%- VIEW v3 base=root;
view.name = "v3";
BLOCK whoami; view.base.whoami() _ " and I live in v3"; END;
END; -%]
[%- VIEW v4 base=root;
view.name = "v4";
BLOCK whoami; view.base.whoami(view=view) _ " and I live in v4"; END;
END; -%]
[% v1.whoami(); # OK : My name is v1 %]
[% v2.presentMe(); # OK : My name is v2 and I live in v2 %]
[% v3.whoami(); # NOK : My name is root and I live in v3 %]
[% v4.whoami(); # OK : My name is v4 and I live in v4 %]
_______________________________________________
templates mailing list
[EMAIL PROTECTED]
http://lists.template-toolkit.org/mailman/listinfo/templates