[Zope] Using TAL outside Zope with path expressions

Rodrigo Dias Arruda Senra rodsenra at gpr.com.br
Sun Jul 25 10:50:37 EDT 2004


On Fri, 23 Jul 2004 17:57:52 -0400
Fred Drake <fdrake at gmail.com> wrote:

> I urge you to consider using the Zope 3 implementation of page
> templates, which has a better separation of the components involved,
> and more documentation on how they work together.

 Indeed. Excelent advice.
 Thank you Fred, for your complete, precise and prompt response!

 For documentation's sake, I have transcripted my test case here.
 Therefore, Z3 newbies (like myself) can find this when looking for:
 'using Zope Page Templates outside Zope context'.

 best regards,

 Rod Senra
 rsenra at acm.org 

------------------------------------------------------------------
<source filename="test_ptZ3.py">
# This code was tested with Zope X3-3.0.0b1 

from zope.pagetemplate.pagetemplate import PageTemplate

context={'some_list':[{'href':'http://localhost','content':'bar1'},
                      {'href':'http://localhost','content':'bar2'}]}    

template1 = """"
<html><body><ul>
 <li tal:repeat="foo some_list">
    <a tal:attributes="href python:foo['href']" 
       tal:content="python:foo['content']">
    </a>
 </li>           
 <li tal:repeat="foo some_list">
    <a tal:attributes="href foo/href" 
       tal:content="foo/content">
    </a>
 </li>           
</ul></body></html>
"""
    
def generateFile(template,context):
    pt = PageTemplate()
    pt.write(template)
    return pt.pt_render(namespace=context)

print generateFile(template1,context)
</source>


More information about the Zope mailing list