[Zope-dev] Help, please!!! __call__ problems with DTML templates

Steve Alexander steve@cat-box.net
Tue, 10 Oct 2000 19:00:51 +0100


Stephen Simmons wrote:

> 
> 2.)  How to convert an arbitrary text string into rendered DTML inside a
> python product method?
> How do you get the object's properties, REQUEST and acquisition context all
> in the namespace?
> 
> I've been trying code like:
>    template = '<span class="purpose"><dtml-var purpose
> fmt="structured_text"></span>'
>    dtml = HTML(template, globals())
>    rendered = dtml(self, REQUEST)

Here's an except from my Python interactive interpreter:

 >>> import DocumentTemplate
 >>> my_dt=DocumentTemplate.HTML("""<dtml-var "1+a">""")
 >>> my_dt(None, {'a':4})
'5'

The object my_dt is callable, and takes the arguments (client, 
namespace). You can put a REQUEST in place of the simple dictionary I 
used above.

If you're trying this, make sure you have the PYTHONPATH environment 
variable set to /your/zope/directory/lib/python


--
Steve Alexander
Software Engineer
Cat-Box limited
http://www.cat-box.net