[Zope] more on DTML Templates

Michael Halle halazar@media.mit.edu
Wed, 15 Mar 2000 09:43:33 -0500


Here is an update on DTML Templates, and a more in depth explanation
of how they work.

** Update ** 

I've updated the DTMLTemplate product to allow commenting out block
definitions and importing blocks using keyword arguments to the
blocks() method.  The new version is 0.3.0

Find DTMLTemplate at:

http://www.zope.org/Members/halazar/Products/DTMLTemplate


** More Information **

Yesterday, Jonothan Farr (jfarr@real.com) asked about the differences
between Templates and the var tag.  Here's a short summary.


The Template product consists of the "dtml-block" tag and the 
"DTML Template" document type.  In a normal document, the dtml-block
described below::

   <dtml-block myblock>
     Block contents      
   </dtml-block>                   
                                 
works exactly like the following dtml::
                              
   <dtml-if myblock>
     <dtml-var myblock>
   <dtml-else>
     Block contents
   </dtml-if>

In addition, blocks can be used to insert structured text directly into
a DTML document (see the documentation for details)::

   <dtml-block mytext fmt="structured-text">
    * this is

    * structured text!
   </dtml-block>



DTML Templates use blocks in an additional way: to define DTML Methods
that other objects can use.  If the Template 'templ' contains the
following lines::

   <dtml-block myblock>
    Block contents
   </dtml-block>

   <dtml-block anotherblock>
    Another Block
   </dtml-block>
   Other, extraneous text.


then 'templ' will have two block methods that other documents can
access in this way::

   <dtml-var "templ.myblock">              ->  "Block contents"
   <dtml-var "templ.anotherblock">         ->  "Another Block"
   
Any document can also import all of the blocks of a Template into a
local namespace::

   <dtml-with "templ.blocks()">
    <dtml-var myblock>
    <dtml-var anotherblock>
   </dtml-with>

You can also refine blocks using Templates::

   <dtml-block myblock>
    <dtml-var "templ.myblock">
    with more stuff added
   </dtml-block>

   <dtml-var templ>

yields::

   Block contents
   with more stuff added
   Another block


** How is this stuff useful? **

I created Templates because I couldn't design complex and attractive
web pages for Zope using Dreamweaver.  I was always pulling out little
chunks of HTML and putting them into individual methods.  These chunks
weren't valid HTML documents, so I couldn't edit them individually.
With Templates, I create one document with all the HTML code I need,
and block out regions of the HTML using dtml-block.  I upload the
templates (once!) to Zope, and instantly I've changed the definitions
of all the template's block methods.  If I need to make further
changes, I can do it quickly in Dreamweaver.

Templates really makes coherent web design with Zope workable.

Hope this extra explanation helps.

Michael Halle
mhalle@media.mit.edu