Presentation is loading. Please wait.

Presentation is loading. Please wait.

Zope Concepts - Zope Page Templates

Similar presentations


Presentation on theme: "Zope Concepts - Zope Page Templates"— Presentation transcript:

1 Zope Concepts - Zope Page Templates
Valentin Baciu Finsiel Romania Tirana, 7 June 2005

2 Concepts ZPT - Zope Page Templates are a web page generation tool
The TAL - Template Attribute Language is an attribute language used to create dynamic templates METAL - Macro Expansion TAL is a macro language built into the ZPT system “Macros are a way to share chunks of presentation, and have the shared stuff appear inline in the template “ – Evan Simpson The TALES - Template Attribute Language Expression Syntax standard describes expressions that supply TAL and METAL with data

3 Zope Page Templates aim
Play nicely with editing tools. What you see is very similarly with what you get. Keep code out of templates, except for structural logic. It is a valid HTML page outside/inside Zope. Allow designers and programmers to work together easily. Dynamically renders XML as well as HTML It is deliberately not as powerful and general-purpose as it could be. It is meant to be used inside Zope in which other objects handle business logic and the tasks unrelated to the page layout.

4 Page Templates vs. DTML DTML is not aimed at HTML designers.
A page with DTML code into it, becomes invalid HTML outside Zope. DTML suffers from a failure to separate presentation, logic, and content (data). DTML can do things that Page Templates can't (e.g. dynamically generate messages ) DTML is enough easy script language to do simple scripts for simple sites DTML adds too much “magic” to object lookup without allowing enough control

5 Replacing DTML with ZPT
DTML: <title><dtml-var title></title> ZPT: <title tal:content="here/title">Page Title</title> - ”here” resolves to the object to which the template is applied - ”tal:content” attribute is a TAL statement that set the text contained by the title tag, and the value "here/title" is an expression providing the text to insert into the tag. DTML:<a href="mailto:<dtml-var webmaster>">contact</a> ZPT:<a tal:attributes="href string:mailto:${here/webmaster}">contact</a> - ”tal:attributes” replaces the value of an attribute or create a new one with dynamic value; “string” evaluates a TALES string expression

6 Replacing DTML with ZPT
DTML: <dtml-var REQUEST> ZPT: <span tal:replace="structure request">request info</span> - ”tal:replace” attribute is a TAL statement that replace the content of an element and removes the element leaving the content; ”structure” – the value it is not html encoded DTML: <dtml-if “title!=‘’"> <dtml-var title> </dtml-if> ZPT: <span tal:replace="template/title" tal:condition="python:title!=‘’"/> - ”tal:condition” conditionally inserts or removes an element - ”python” executes a python expression

7 Replacing DTML with ZPT
<dtml-in somesequence> <dtml-let doc_title=“_[‘sequence-item’].title”> <dtml-var doc_title> <br> </dtml-let> </dtml-in> ZPT: <span tal:repeat="item here/somesequence"> <span tal:define=“doc_title item/title” tal:replace=“doc_title“/><br> </span> - “tal:repeat” replicates a sub-tree of your document once for each item in a sequence; the expression should evaluate to a sequence - “tal:define” defines variables (local variables are default)

8 Using Macros You can define macros with tag attributes similarly to TAL statement <p metal:define-macro=“footer”> Last updated <span tal:replace=“here/ZopeTime”/> </p> If you change the macro then all page templates that use the macro will automatically reflect the change. You can use macros from other page templates by referring to them through the macros attribute of the page template in which they are defined. <p metal:use-macro=“container/macros_page/macros/footer”> Macro goes here - “metal:define-macro” -- macro is identified by a path expression using this statement - “metal:use-macro” – replace the statement element with named macro

9 Using Slots Common use of slot is to provide default presentation which you can customize In the following example, the slot definition is just an empty span element <div metal:define-macro=“footer”> <span metal:define-slot=“info”/> </div> You can fill the slot with any html code you want, for example : <div metal:use-macro=“container/macros_page/macros/footer”> <b metal:fill-slot=“info”> <a href=“info_html”>Info</a> </b>


Download ppt "Zope Concepts - Zope Page Templates"

Similar presentations


Ads by Google