[Zope-dev] Help, please!!! __call__ problems with DTML templates
Steve Alexander
steve@cat-box.net
Tue, 10 Oct 2000 18:44:09 +0100
Stephen Simmons wrote:
>
> 1.) How do you magically get the DTML context from '<dtml-var A>' without
> having to resort to '<dtml-var "A(_,REQUEST)">' in the templates?
Give your class a class attribute of isDocTemp=1. This tells the DTML
method calling machinery that you want to receive the namespace as
REQUEST as the third argument to your __call__ method.
There was a thread on this in zope-dev on and around 26 September,
subject "more __call__ ..."
> In the __call__ methods of different classes, I've seen some code like:
> 'if REQUEST is None and not kw: REQUEST=self.REQUEST' (from
> Catalog.py)
Your method will usually get called with its third argument as the
namespace, or REQUEST. However, sometimes, it may just be called with a
"self" argument. The code in Catalog.py is falling back on getting the
REQUEST out of the self argument, if it is not explicitly passed a
namespace to work with.
> I can't see any consistency in what these classes are doing, so I don't know
> what I need to do.
Most developers would like more consistency here :-)
I'm hoping that all this will be much much clearer for Zope 2.3. That
doesn't help much for now though.
> 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())
If all you want to do is render some Structured Text, you can import and
use the StructuredText module directly.
> P.S. ChrisW, searching NIP for "__call__" returns every message with 'call'
> in it, which is not quite the same thing!
For cases like that, I have downloaded the plaintext mail archives as
available from http://www.zope.org/Resources/MailingLists
I then use unix grep on them to search for just what I need.
--
Steve Alexander
Software Engineer
Cat-Box limited
http://www.cat-box.net