[ZDP] BackTalk to Document The Zope Book (2.5 Edition)/Appendix C: Zope Page Templates Reference

nobody@nowhere.com nobody@nowhere.com
Thu, 12 Sep 2002 10:21:59 -0400


A comment to the paragraph below was recently added via http://www.zope.org/Documentation/Books/ZopeBook/current/AppendixC.stx#3-52

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

      Inserting HTML/XML::

        <p tal:content="structure here/getStory">marked <b>up</b>
        content goes here.</p>

        % Anonymous User - May 23, 2002 12:43 pm:
         This snippet is unclear unless we know what getStory
         returns.  Is it HTML?  Be clear.  

         Also, what would happen if you said "structure" but
         only text were returned, or vice-versa?

        % fdrake - May 24, 2002 4:41 pm:
         getStory() is expected to return HTML (or XML if you're using XML instead).
         Nested TAL markup will be interpreted.

         If it returns plain text it needs to be valid when parsed as an HTML fragment,
         so it depends on whether the < or & characters are included.

        % Anonymous User - Sep. 10, 2002 2:34 am:
         A problem I can find no documentation on related to this, 
         is how can you access variables defined in a page template,
         in another page template called to be the content of a tag?
         For example, say the getStory above is actually a page template,
         and you modify the call like this:

         <p tal:define="myvar string:whatever"
            tal:content="structure here/getStory">marked <b>up</b>
               content goes here.</p>

         Now how can you access myvar from within getStory?

        % Anonymous User - Sep. 12, 2002 10:21 am:
         I solved the above by putting calling the pagetemplate from python. Instead of using tal:content="structure
         here/getStory" i use:
         tal:content="structure python:context.getStory(myvar='whatever')"

         Now from within the getStory page template options/myvar can be accessed. I 
         think this is a good trick to add to the documentation... explaining this 
         additional capability, using python to insert an embedded page template  within 
         another page template where one needs to pass some variable from the outer 
         template to  the inner template. Unless there is a better way that I don't know 
         about... then that would be good to document also.