[Zope3-Users] Re: How to render PageTemplate manually?
Pawel Lewicki
lewicki at provider.pl
Thu Jan 5 08:14:41 EST 2006
> --------------------------------------------
> from TAL.TALInterpreter import TALInterpreter
> from Products.PageTemplates.Expressions import getEngine
> from Products.PageTemplates.PageTemplate import PageTemplate
> from cStringIO import StringIO
>
>
> data = {
> 'test': 'Testing text',
> }
> t1='<h1 tal:content="test"></h1>'
> context = getEngine().getContext(data)
> buffer = StringIO()
> pt = PageTemplate()
> pt.write(t1)
> pt._cook()
> TALInterpreter(pt._v_program, pt._v_macros, context, buffer)()
> macro = buffer.getvalue()
> print macro
And z3 version... ;)
------------------
from zope.tal.talinterpreter import TALInterpreter
from zope.tales.tales import ExpressionEngine, Context
from zope.pagetemplate.pagetemplate import PageTemplate
from cStringIO import StringIO
data = {
'test': 'Testing text',
}
t1='<h1 tal:content="test"></h1>'
context = Context(ExpressionEngine(),data)
buffer = StringIO()
pt = PageTemplate()
pt.write(t1)
pt._cook()
TALInterpreter(pt._v_program, pt._v_macros, context, buffer)()
macro = buffer.getvalue()
print macro
-----------------
Pawel
More information about the Zope3-users
mailing list