As an experiment, more to see if it was possible or not, I just extended %SECTION to support an "if" type and an ELSE clause. This lets you write something like this:
%SECTION{type="if" condition="defined FLUB"}%
FLUB is defined
%ELSESECTION%
FLUB is *not* defined
%ENDSECTION%
Fun, eh? The syntax is rather clumsy, but it shows how easy it is to add something like this. It's basically what the IfDefinedPlugin does, if I'm not much mistaken, but with syntax consistent with the rest of the core.
The syntax is evaluated after verbatim and literal sections are protected, just before the startRenderingHandler, and before any other TWiki variables are evaluated.
This means that any TWiki variables inside the failing side of the condition are never evaluated. So you can't "build" a %SECTION{type="if" out of other TWiki variables (though I have evaluated them inside the condition value).
This construct cannot be used to conditionally assign TWiki variables.
A patch (against rev 14684) is attached to ExtendSECTIONToSupportConditionals. I did not write any unit tests, and I have absolutely no idea of the effect on performance. It was just an hour long experiment.
Comments
WhitBlauvelt - 15 Sep 2007:
Good tip. Could this easily be used to display a section of the page only if the reader is a member of a particular Group? I'm thinking of pages where read access is general, but write access is limited to a Group. This Group also wants to keep a block of links for their own use, which since they go to webs where the general reader has no access at all, there's no reason to clutter the page with. This should be doable if the right variables are available at that point in the process. Is there a way to display all available variables, to see what might be used in a conditional in a particular page context?
CrawfordCurrie - 17 Sep 2007:
%ALLVARIABLES%