[pmwiki-users] Nested IF
Peter & Melodye Bowers
pbowers at pobox.com
Thu Apr 24 08:24:43 CDT 2008
I don't know how often people have need for a nested conditional, but I've
put together a recipe that supports it. You can find it here:
http://www.pmwiki.org/wiki/Cookbook/NestedIf
It uses markup in this form:
(:n-if true:)it is true(:n-if false:)it is false(:n-else:)it is not
false(:n-ifend:)(:n-else:)it is not true(:n-ifend:)
Or, placed on multiple lines and formatted for easier reading:
(:n-if true:)
it is true
(:n-if false:)
it is false
(:n-else:)
it is not false
(:n-ifend:)
(:n-else:)
it is not true
(:n-ifend:)
All conditions are identical to the existing (:if ...:) conditions - same
code is used, so any extensions you've made should also work.
This is probably obvious, but just to be sure... Note that (:n-if:) does NOT
end the previous if-block as (:if:) does in normal pmwiki conditionals.
The "n-" prefix to each of the if, else, ifend can actually be several
different things:
n (:nif ...:)
n- (:n-if ...:)
nest (:nestif ...:)
nest- (:nest-if ...:)
nested (:nestedif ...:)
nested- (:nested-if ...:)
(I've illustrated each with the if, but the same prefixes can be affixed to
the "else" or the "ifend".)
Hope this helps.
-Peter
PS I don't think much of the way this looks in terms of being understandable
and intuitive. (That's why I've offered so many alternatives - in hopes of
finding one that looks right.) If somebody has a better idea on the markup
I'd be all ears... The recipe could actually over-ride the existing (:if
...:) markup, but then most existing conditionals would have to be altered
and existing sites would be unable to use it.
More information about the pmwiki-users
mailing list