[Zope] Checking multiple variables existence

Justin Dunsworth justin.dunsworth at gmail.com
Tue Jan 24 18:14:47 UTC 2012


Thanks for the response.

I could do that but it isn't really getting rid of the original problem.
Using my original example I'd be turning this:
<dtml-if var1>
  <dtml-if var2>
    <dtml-if var3>
    <dtml-else>
    </dtml-if>
  <dtml-else>
  </dtml-if>
<dtml-else>
</dtml-if>

into:

<dtml-unless var1>
<dtml-call "REQUEST.set('var1','')">
</dtml-unless>
<dtml-unless var2>
<dtml-call "REQUEST.set('var2','')">
</dtml-unless>
<dtml-unless var3>
<dtml-call "REQUEST.set('var3','')">
</dtml-unless>

<dtml-if "var1!='' and var2!='' and var3!=''">
<dtml-else>
</dtml-if>

Thereby increasing the lines of code used, albeit in an initially
"prettier" format when it gets down to the checking of said variables.

I figured if there was an answer for my problem then it'd be an easier
method that I just overlooked. If not then I'll just go with it.

On Tue, Jan 24, 2012 at 11:43 AM, Jaroslav Lukesh <lukesh at seznam.cz> wrote:

> Yes, use like that
>
> <dtml-unless var1>
> <dtml-call "REQUEST.set('var1','')">
> </dtml-unless>
>
>
>
> ----- Puvodní zpráva ----- Od: Justin Dunsworth
>
> These are required to be set, though.. right?
>
>
> Doing:
> <dtml-call "REQUEST.set('var_one','OK')">
> <dtml-call "REQUEST.set('var_two','OK')">
>
>
> <dtml-if "var_one=='OK' and var_two=='OK'"> Set
> <dtml-else> Not Set
> </dtml-if>
>
>
> works but taking away var_two and I get a NameError: name 'var_two' is not
> defined. This is what I'm trying to check is if they exist. Not
> particularly looking to match them to anything just yet but rather just to
> see if they exist. If they throw an error then it's not working.
>
>
> On Tue, Jan 24, 2012 at 11:08 AM, Jaroslav Lukesh <lukesh at seznam.cz>
> wrote:
>
> it works:
>
> <dtml-if "var1=='OK' and var2==3 and var3 in ('a',1,'1') and var4 != 'OK'
> and var5">
>
> note1: var5 is string, true when <>'' nor None but must exists
>
> note2: var5 is int, true when <>0 nor None but must exists
>
> <dtml-else>
> </dtml-if>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.zope.org/pipermail/zope/attachments/20120124/aff5ed65/attachment.html>


More information about the Zope mailing list