[pmwiki-users] Nested IF

Patrick R. Michaud pmichaud at pobox.com
Thu Apr 24 11:24:54 CDT 2008


On Thu, Apr 24, 2008 at 05:13:49PM +0200, Peter & Melodye Bowers wrote:
> > Thursday, April 24, 2008, 2:24:43 PM, Peter & Melodye Bowers wrote:
> > (:if1 ....:)
> >   ...
> > (:if2 ....:)
> >   ....
> > 
> > (:elseif2 ....:)
> >   ...
> > (:if2end:)
> > (:elseif1 ...:)
> >   ...
> > (:if1end:)
> > 
> > This will make it much clearer from where to where a 'nesting' goes.
> 
> Would the number need to be prescriptive or just descriptive?  In other
> words, if someone wrote (:if1 ...:) ... (:if2end:) then should there be an
> error?  Or should it not match the markup at all (thus leaving it verbatim
> without replacing anything)?  Or should the difference in numbers just be
> ignored?
> 
> I like the idea of a number because it differentiates from a normal
> if/else/ifend markup while still looking like "if" ("if0" looks more like
> "if" than "nested-if" or the other options).  Also it does help since a
> wiki-page doesn't usually allow for nicely indented code to help you find
> your way through the nesting, so these numbers could be very valuable...

FWIW, the (:div1:), (:div2:), etc. markups work simply by matching
the numbers.  It's nice doing it this way because you don't have to
worry about providing all of the explicit ends.  For example, an author
can write (showing with indents here for clarity):

    (:div1:)
      ...
      (:div2:)
      ...nested div...
    (:div1end:)

and the nested div is automatically closed without the need for an
explicit (:div2end:) from the author.  

So for consistency we should do the same for nested if's.  In other
words, in the above nested if example could be written:

    (:if1 ... :)
      ...
    (:if2 ... :)
      ...
    (:elseif2 ... :)
      ...
    (:elseif1 ... :)
      ...
    (:if1end:)

The "elseif1" clause would automatically imply closing the
nested "if2" part, so the author isn't required to write
the (:if2end:)  (but it doesn't hurt to do so).

This is such a fantastic and straightforward idea (thanks, Hans!)
that I'm now adopting this markup and approach as a PmWiki 
CoreCandidate and planning to add it into the core.  I will
probably try to do this today or over the weekend.  Others are 
welcome to implement something like it in recipes, but just be 
aware that PmWiki should have its own implementation soon 
so it may be best to avoid conflicts.

Pm



More information about the pmwiki-users mailing list