[Zope] Re: dtml-let and product

Tres Seaver tseaver at palladion.com
Fri Feb 22 00:03:56 EST 2008


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Wayne Volkmuth wrote:
> I have a simple test Zope product inheriting from Cacheable, PropertyManager and SimpleItem.
> 
> Say I have a dtml method at http://myzopeinstance.com/testdtml with contents
> <dtml-let myvar="'hello world'"><dtml-var testproduct></dtml-let>
> 
> I'd like "myvar" to be available in the__call__ method of testproduct.  I don't know how to do that.
> 
> Here's my testproduct __call__ method:
> 
>     def __call__(self, client=None, REQUEST=None, **kw):
>         foo="1. client:"+str(client)+"<BR>" \
>            +"2. REQUEST:"+str(REQUEST)+"<BR>" \
>            +"3. kw:"+str(kw)+"<BR>" \
>            +"4. getattr(..REQUEST..):"+str(getattr(self, "REQUEST", None))+"<BR>" \
>            +"5. getattr(..client..):"+str(getattr(self, "client", None))+"<BR>" \
>            +"6. getattr(self, myvar...):"+str(getattr(self, "myvar", None))+ "<BR>" \
>            +"7. aq_get(self, myvar...):"+str(aq_get(self, "myvar", None))+ "<BR>"
>         return foo
> 
> From poking around I was expecting "myvar" to be accessible
> somewhere  from that list either directly or as an attribute of one
> of the objects, but it's not. Every call (via a web browser) displays
> None for every line except #4, the getattr(self, "REQUEST", None)
statement.

Two things:

 - 'myvar' is not defined as an attribute of your object:  it is a name
    in one layer of the DTML namespace, created by the '<dtml-let>'.

 - Callables referenced by name in a var (e.g., your
   '<dtml-var testproduct>') are called *without* arguments.

To get the mapping passed, you need to implement the method,
'__render_with_namespace__', which will then be passed the
multi-mapping as an argument.  E.g.::

  def __render_with_namespace__(self, md):
      myvar = md['myvar']
      # ....



Tres.
- --
===================================================================
Tres Seaver          +1 540-429-0999          tseaver at palladion.com
Palladion Software   "Excellence by Design"    http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHvle8+gerLs4ltQ4RAmJrAKCV7k8t/9kLzMxNJlqX/uQ7bSDnHwCfdN6i
7bRTszqprybjxx6IgxaK2J8=
=atpX
-----END PGP SIGNATURE-----



More information about the Zope mailing list