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

webmaster at zope.org webmaster at zope.org
Fri Apr 2 15:42:21 EST 2004


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

---------------

    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
    by":http://dev.zope.org/Wikis/DevSite/Projects/ComponentArchitecture/FrontPage
    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
       happily.
       I'm not sure if this would be exactly the same if you were running zope on a remote computer, but I presume
       so.

      % 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:tag="value"

       "TAL tags" are embedded within standard HTML tags

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

       tal:content
       tal:replace
       tal:condition
       tal:repeat
       tal:attributes

       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

      % Anonymous User - Dec. 2, 2003 9:18 pm:
       useful.  thanx.  you cld write the next chapter..

       ;7]

      % ExileJedi - Jan. 18, 2004 4:53 pm:
       Anonymous from 11/21/03 - nice summary, and a fair assessment of what needs further elucidation. Rock on. :-)

      % Anonymous User - Apr. 2, 2004 8:51 am:
       nice job. Simple and clear. I wish this summary was at the beginning of the chapter.

      % Anonymous User - Apr. 2, 2004 3:42 pm:
       For "Best Results", the content vs replace section in the summary comment should change to
       -
        To see the difference between tal:replace and tal:content, create
        a page templage and include the following in the body:

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

       "tal:replace" affects the tag it is an attribute of.

       In the original line:
       <b><span tal:replace="user/getUserName"></span></b>

       the "tal:replace" will replace the <span> tag, leaving the bold tags.
       The rendered content will be exactly the same as the "tal:content" line.

       Also, I belive the exact zope equivalent of the python var "context.title" is "here/title"
       I believe "here" is the current object, I'm not entirely sure what "template" is.



More information about the ZDP mailing list