How to use Zope Page Templates in ZMSAutor: Dr. H. Merz, cyberconcepts.de, 11.08.2005 Zope Page Templates (ZPT) with TAL and METAL elements can be readily used together with ZMS. There is no special support for ZPT/TAL in ZMS, e.g. you can not directly use ZPT/TAL in methods defined in Special Objects, but you can call a Zope Page Template from a DTML method as well as include the output of a DTML method in a Zope Page Template.
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). More information on Zope Page Templates can be found in the Zope book
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. <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. <dtml-var "zms_templates.my_zpt_view(object=this())">
where the topmost HTML element of the template contains a <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. <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): <html>
<head>
<title tal:content="template/title">The title</title>
</head>
<body>
<p>
<span tal:replace="structure here/test_dtml">
This will be replaced by calling a DTML method.
</span>
</p>
<p>
<span tal:replace="structure python: here.test_dtml(
here, request, my_parameter='hello')">
This will be replaced by calling a DTML method.
</span>
</p>
</body>
</html>
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> <p> This is the <dtml-var document_id> Document in the <dtml-var title_and_id> Folder. </p> <p>Parameter: <dtml-var my_parameter missing="not given"> </p> |
Home |
Sitemap |
Druckversion |
Seitenanfang |
Impressum |
pressinfo
© 2001-2008 Hoffmann+Liebenberg GmbH, SNTL Publishing GmbH & Co KG
|
ZMS is a partner project of medvalue.net