Hi everybody,

I was surprised to find out that very few messages in this list talk about the 
VIEW directive. I know, it is "experimental" ... but has been there for a 
couple of years now. I hope this feature will still be there in TT3 (or a 
construct with equivalent power). So this mail is just to stir the discussion 
about who uses it and how.

At our site we used it to build an OO-style framework of templates, with 
subclassing and inheritance. It has been in production for more than one year, 
so it is no longer "experimental" for us.

Views allow us to set up the late binding mechanism and "late fixpoint" 
operation needed for OO stuff. Basically it works as follows :


+============+
|File base.tt|
+============+

[%- VIEW base; 

    # ATTRIBUTES (may be redefined in subclasses)

    view.attr1 = "attribute 1 from base class";
    ...
    # METHODS : see blocks below
   -%]


    [%############################################################%]
    [%- BLOCK main -%] 
    [%############################################################%]
    <html>
      <head>
      [% view.head() %]
      </head>
      <body [% view.onload() %]>
      [% view.body() %]
      </body>
    </html>
    [%- END # BLOCK main -%] 

    ... etc. for other blocks


[%- END; # VIEW base

    # Execute main (late fixpoint) unless we were called from a subview
    base.main() UNLESS component.caller -%]

+================+
|File subclass.tt|
+================+


[%- PROCESS base.tt; # load base class

    VIEW subclass    # define subclass
      base=base;     # inherit from base

    view.someAttr = "redefined in subclass"; 
-%]

    [%############################################################%]
    [%- BLOCK body -%] 
    [%############################################################%]
     ... some specific content ..
    [%- END # BLOCK body -%] 



[%- # End of subclass "methods"
    END; # VIEW subclass
  
    # Execute main (late fixpoint) unless we were called from a subview
    subclass.main()  UNLESS component.caller -%]


Laurent Dami
Conseiller en systèmes d'information
Palais de Justice - Etat de Genève
Case postale 3966
Place du Bourg-de-Four 3, 1211 Genève 3
+41 (22) 327 20 64 (direct), +41 (22) 327 20 37 (service)
http://cui.unige.ch/~dami





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

Reply via email to