DTML is the classic templating language used in Zope that is also used by ZMS. For a few years now Zope also provides a new templating system called 'Zope Page Templates' (ZPT) that offers advantages especially when building complex template structures. ZPT uses a special syntax for providing dynamic elements called "Template Attribute Language" (TAL) and offers the inclusion of macros (other templates or parts of them) using the "Macro Expansion Template Attribute Language" (METAL).

Calling ZPT from DTML

Create a ZPT in an appropriate place in the folder hierarchy - e.g. in the top folder of the ZMS site parallel to the "content" folder or directly within it. You can then include this template e.g. in the Template/bodyContent method by calling it like this:

<dtml-var my_zpt_view>

When I have to create a larger number of templates I usually collect them in a sub-folder (e.g. called zms_templates) of the top folder to avoid cluttering up the top folder with a lot of templates.
Then one has to make sure that the template will not use the "context" (or "here") variable to access the content object, because this will be the folder the template is situated in; instead I define a variable called "object" that I give to the template as a parameter:

<dtml-var "zms_templates.my_zpt_view(object=this())">

where the topmost HTML element of the template contains a tal:define statement like this:

<html tal:define="object options/object" ...>

In this zms_templates folder one can also put Python scripts that implement the procedural parts of an application.
All methods of the ZMS objects are also available in TAL statements, e.g. you may use the following element

<div tal:content="python:object.getObjProperty('name_of_property')" />

to retrieve an object's property.

Calling DTML methods from ZPT

You can just call a DTML method in a path or python expression, like any other method or Python script, see the <span..> tags in the example below (test_dtml is a DTML method):

    <title tal:content="template/title">The title</title>

      <span tal:replace="structure here/test_dtml">
          This will be replaced by calling a DTML method.
      <span tal:replace="structure python: here.test_dtml(
                          here, request, my_parameter='hello')">
          This will be replaced by calling a DTML method.


Don't forget to use the "structure" keyword to prevent quoting of the HTML special characters provided by the DTML method. The second exemple shows how to provide the DTML method with parameters. The DTML methode (test_dtml) I used for this example looks like this:

<h2><dtml-var title_or_id> <dtml-var document_title></h2>
  This is the <dtml-var document_id> Document
  in the <dtml-var title_and_id> Folder.
  <dtml-var my_parameter missing="not given">

Erstellt von: Dr. H. Merz, cyberconcepts.de , erstellt am:  27.06.2008 , zuletzt geändert: 21.03.2017