[Zope] - namespace problem

Jim Fulton jim@digicool.com
Thu, 31 Dec 1998 12:06:12 +0000


Richard Jones wrote:
> 
> The following DTML does not work:
> 
> <!--#if foo-->
>  <p>foo found!
> <!--#else-->
>  <!--#call "_.namespace(foo=1)"-->
>  <p>foo inserted! <!--#var foo-->
> <!--#/if-->
> 
>    It barfs with a NameError on foo. If I change the #call to a #with and use
> that to enclose the #var foo, then it works. I'd like to suggest that the
> description of the _.namespace function in the DTML reference include the
> return value (ie. "it returns a new namespace to be used in a #with" or
> somesuch).

OK, the documentation could be clearer on this point.
We'll fix it.

>    Given that the #call and _.namespace combination aren't going to do what I
> want to do, how can I do it?

With a #with and namespace combination:

  <!--#if foo-->
   <p>foo found!
  <!--#else-->
   <!--#with "_.namespace(foo=1)"-->
      <p>foo inserted! <!--#var foo-->
   <!--#/with-->
  <!--#/if-->

But it looked like you had discovered that.

> I've also tried REQUEST.set() but couldn't get
> that to work at all.

Hm, that should work too. The following worked
for me:

 <!--#if foo-->
  <p>foo found!
 <!--#else-->
  <!--#call "REQUEST.set('foo',1)"--> 
  <p>foo inserted! <!--#var foo-->
 <!--#/if-->

Jim

--
Jim Fulton           mailto:jim@digicool.com
Technical Director   (540) 371-6909              Python Powered!
Digital Creations    http://www.digicool.com     http://www.python.org

Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email
address may not be added to any commercial mail list with out my
permission.  Violation of my privacy with advertising or SPAM will
result in a suit for a MINIMUM of $500 damages/incident, $1500 for
repeats.