[pmwiki-users] ZAP conditional syntax

Ben Stallings ben at interdependentweb.com
Thu Mar 8 21:16:30 CST 2007


Dan replied to Jiri,
> > (:zap condition="condition" fields="field1,field2" true="value1,value2"
> > false="value3,value4":)
> Can't really do that without creating a new markup which I would
> rather avoid.  According to my markup definition, it has to look like
> (:zap if*="text...":).

At the risk of getting too techie for the users list...

When I wrote UpdateForm's (:update:) markup definition, I copied it (and 
the series of function calls that parse it) shamelessly from that for 
(:input:) tags, which is very flexible -- it allows for any number of 
parameters.  I think if you used the same thing for (:zap:) you would 
find that you could still handle if* parameters (for backward 
compatibility) while gaining the ability to handle multiple-parameter 
tags like the one above.  You're all about flexibility, Dan; why limit 
your tags to one parameter?  :-)

> With these related options:
> 
> (:zap if="condition ? field1=value1` field2=value2 : field1=value3 `
> field2=value4":)
> 
> Replaces , with ` which is almost never used to help avoid accidental
> bugs from user input.

I think this is a mistake.  Speaking for myself, I'm used to typing 
commas or spaces or semicolons between parameters.  Not backticks.  The 
only place I've ever used those is in MySQL queries, where they're 
uniters, not dividers.  Also they're usually optional.

It seems to me the only reason any delimiter is necessary between the 
field assignments is because there may be spaces in the values, and if I 
understand you correctly, your objection to using commas is that there 
may be commas in the values as well.  And you can't put quotes around 
the values because they're already in quotes and your markup only allows 
one set of quotes.  So if you're going to use backticks, how about

(:zap if="condition ? field1=`value1` field2=`value2` : field1=`value3` 
field2=`value4`":)

No, now that I've suggested it, I take it back.  I remember: I have used 
backticks in another place: in the ill-advised markup I wrote for 
SelectQuery: {`fieldname`} and {(if `fieldname` ? then : else)}.  Then I 
was very intentionally following in the footsteps of MySQL, using 
backticks to indicate field names, *not* values.  Using them to surround 
values would just confuse the issue further...

No, I think you'd be better off if the (:zap:) tag allowed multiple 
parameters.  But that's just my opinion.

> (:zap if="condition ? field1=value1, field2=value2 (false)
> field1=value3 , field2=value4":)
> 
> Another indicator beside : for what to do when the condition fails...
> Other options include
> ! or :: or || (!), etc...  Again, the more common the delimiter, the
> more likely your conditional will be compromised...

And again, I don't think that's the point... wiki markup needs to be 
easy to remember and easy to type.  : already means "else" in dozens of 
contexts (admittedly, all of them outside the wiki world)... "else" 
means "else" in even more (including PmWiki), so if you're looking for 
something clearer than : I suggest the word else or else: or :else: to 
set it off nicely.

But on the other hand, you may be onto something with (false).  If you 
did something like

(:zap if="condition (true: field1=value1 field2=value2) (false: 
field1=value3 field2=value4)":)

that would raise the exciting possibility of using it like a case 
statement (which an if/then/else is basically anyway):

(:zap if="variable (yes: field1=value1 field2=value2) (no: field1=value2 
field2=value3) (maybe: field1=value3 field2=value1)":)

Or if the (:zap:) tag allowed multiple parameters,

(:zap field1,field2 condition=variable yes="value1,value2" 
no="value2,value3" maybe="value3,value1":)

Good luck figuring something workable out of all these suggestions!  --Ben



More information about the pmwiki-users mailing list