[Zope] Passing object name or id to DTML method

Joel Burton joel@joelburton.com
Mon, 4 Mar 2002 16:48:39 -0500 (EST)


On Mon, 4 Mar 2002, Vinod Shrestha wrote:

> I have a DTML method similar to the one below. I want to call this
> (from an html link) with an argument that is the name of the object
> xxx (eg. http://localhost/zope/test?xxx=item1_id). The idea is to use
> the same DTML method to render many instances of the object type.
> Being a newbie, I would appreciate your help--an example would be
> nice. Thanks.
>
> <dtml-with xxx>
> ....
> </dtml-with>

Well, it depends what the object is that you want rendered. For example,
with content from a relational DB (like PostgreSQL or MySQL), you might be
passing a primary key. So, your code would look like:

<dtml-with "MyZSQLMethod({'primary_key_field':xxx})">
  <dtml-var first_name> <dtml-var last_name> ...
</dtml-with>

If the object being passed was a DTML Document that had properties you
wanted you can just use it like:

<dtml-with "_[xxx]">
  <dtml-var first_name> <dtml-var last_name> ...
</dtml-with>

The _[xxx] syntax means "look up the value of the variable xxx in the
current namespace". This is different than _["xxx"] which means look up
the object called "xxx" in the namespace ('xxx' is literally used, not
the value of the variable.)

When you say simply <dtml-with xxx>, you're saying the same thing as
_["xxx'].

Hope this helps. It might be helpful to be specific about what kind of
information you're displaying and what kind of objects these are.

--

Joel BURTON  |  joel@joelburton.com  |  joelburton.com  |  aim: wjoelburton
Independent Knowledge Management Consultant