[pmwiki-devel] PmWiki request

Patrick R. Michaud pmichaud at pobox.com
Tue Dec 12 08:02:27 CST 2006


On Tue, Dec 12, 2006 at 06:34:31AM -0500, The Editor wrote:
> Recently had an idea for tying zap's conditionals in PmWiki's far more
> powerful conditional system.  It would also decrease the learning
> curve as it would use more familiar syntax.
> 
> Basically the idea is to use things like
> 
> (:input hidden ifexists "parameter|action":) // exists must first be defined

Seems to me that

  (:if exists parameter:)(:input hidden action:)(:if:)

is only few characters longer but more consistent.  Plus you
get complex expressions for free.

> My question is this:  What function do I call to get the true/false
> returned to me.  I've looked at these two possibilities:
> 
> function CondExpr($pagename, $condname, $condparm) {
> function CondText($pagename,$condspec,$condtext) {
> 
> But to be honest, I can't make much heads or tails of either of them,
> but dont' think either will work for what I need, as they seem to be
> locked into returning markup only.  Is there someway PmWiki could be
> rewritten slightly to break out the part that determines if true or
> false into a separate function?  Or if what I need already exists,
> could someone point the way?

The CondExpr() function returns true or false depending on the
expression passed in $condparm.  So, it already does what you're
asking for.

The CondText() function can also do exactly what you're asking
here, and is more general.  The $condspec parameter is the 
conditional part of the (:if:) directive, the $condtext parameter
is what to return if the conditional part is true.  (If the conditional
is false, CondText() returns an empty string.)

So, if you want to use CondText as a true/false indicator, simply 
use 'true' as the $condtext parameter:

    if (CondText($pagename, $condition, true)) ...

To illustrate using the condition of your original post:

    $condition = "expr exists Group.Name && ! exists OtherGroup.Name";
    if (CondText($pagename, $condition, true)) {
      ## Group.Name exists and OtherGroup.Name doesn't
      ...
    }

Pm



More information about the pmwiki-devel mailing list