[ZDP] BackTalk to Document The Zope Book (2.6 Edition)/Using Zope Page Templates

webmaster at zope.org webmaster at zope.org
Fri Nov 21 04:32:55 EST 2003

A comment to the paragraph below was recently added via http://zope.org/Documentation/Books/ZopeBook/2_6Edition/ZPT.stx#2-92


    Zope's "Content Management Framework":http://cmf.zope.org (CMF)
    solves this problem by providing an assortment of rich content
    components.  The CMF is Zope's content management add on. It
    introduces all kinds of enhancements including work-flow, skins,
    and content objects. The CMF makes a lot of use of Page
    Templates. A later release of Zope will probably include
    technologies "from and inspired
    the CMF.

      % Anonymous User - Nov. 4, 2003 11:09 am:
       Having completed this chapter I now have a question:
       How does one display a Page Template?

       I have been told in paragraph one of this chapter that I can edit them from outside through the web.

       I have been told to use the "Test" button within Zope, but are there other possibilities?

      % Anonymous User - Nov. 19, 2003 1:51 am:
       My Zope server is running on http://localhost:8080
       I made a zope page template named 'display' in the folder 'sandbox' via the html management interface.
       When I pointed my browser to http://localhost:8080/sandbox/display the template displayed itself quite
       I'm not sure if this would be exactly the same if you were running zope on a remote computer, but I presume

      % Anonymous User - Nov. 21, 2003 4:32 am:
       Summary of my Understanding from this chapter:
       (It could all be completely wrong)

       TAL basically works by substituting one thing for another.
       (The substitution takes place when the page is rendered by Zope)

       "TAL tags" are always of the form:


       "TAL tags" are embedded within standard HTML tags

       "TAL tags" which we have met in this chapter are:


       The easiest "TAL tags" to understand and tal:content and tal:replace

       tal:content substitutes its 'value' for whatever is enclosed by the
       HTML tag within which it is embedded.

       Example 'values' which the tal:content might take are:

       template/title    {The title of the template}
       request/URL       {The current URL}
       user/getUserName  {The current users name}

       (Its these "value" things which I understand the least)

       To test these out, create a template, give it a title and include
       in its body:

       <span tal:content="template/title"></span>
       <span tal:content="request/URL"></span>
       <span tal:content="user/getUserName"></span>

       I suspect that 'template', 'request' and 'user' are builtin Zope objects.
       I suspect that 'title' is a method of the 'template' object, 'URL' is a method of the 'request' object and
       'getUserName' is a method of the 'user' object.
       tal:replace is pretty simmilar to tal:content, except it replaces
       the whole tag, rather than just what is enclosed by the tag.

       To see the difference between tal:replace and tal:content, create
       a page templage and include the following in the body:

       <b><span tal:content="template/title"></span></b>
       <b><span tal:content="request/URL"></span></b>
       <b><span tal:content="user/getUserName"></span></b>
       <b><span tal:replace="template/title"></span></b>
       <b><span tal:replace="request/URL"></span></b>
       <b><span tal:replace="user/getUserName"></span></b>

       Two of hese built in objects: 'template', 'request' and their methods can also be accessed by python scripts,
       but the third one 'user' doesn't seem to be accessable. I have no idea why. The syntax is also a little bit
       different when accessing these object/variable/property/vaue/things from python rather than TAL.
       For python we write:

       context.title               instead of    template/title
       context.REQUEST.URL()       instead of    request/URL

       To see how this works create two python script objects.
       Name them 'the_title' and 'the_url'

       Cut and paste the following into 'the_title'

       ## Script (Python) "files"
       return context.title

       Cut and paste the following into the_url

       ## Script (Python) "files"
       return context.REQUEST.URL

       Now change the ZPT so that it contains the following body:

       <span tal:content="template/the_title"></span>
       <span tal:content="template/the_url"></span>

       What is happening now is that the tal:content tag is taking as 
       its value the output of the scripts the_title and the_url

       Somehow 'template' gets mapped onto 'context' but I'm not sure how.

       Also I can't seem to find a way to acces 'user' via python.
       Its all quite confusing.

       I think that A LOT more discussion about the 'values' which tal attributes can take is needed.
       Also some discussion about which objects python scripts can access by default.
       And what the relationship is between the builtin object/value/property things which TAL can access,
       and the buildtin object/value/property things which python scripts can access.

       I hope these comments are useful to somebody who is going to rewrite this section, 
       rather than just annoying to other people who are trying to read it ;-P

More information about the ZDP mailing list