This question about Documentation: Needs Documentation Task
Limits of If Statements
I want to understand the limits of IF statements as they relate to display or hiding of navigation and other multi-line data based on login or other factors. Reading the IF topic here:
IfStatements
It appears that IF statements work only as single line statements. For example, in PHP, Perl, and other languages, conditional statements can display or not display multi-line data. You might use the presence or absence of form data to display either a thank you message or a contact form. Does the IF statement in Foswiki allow multi-line data display?
Specifically, in the Beginners Start Here topic, Slide 8 says, "It is common that the administrator simplifies the toolbox so you may not have all these items in your menu bar" here:
BeginnersStartHere
How is that done? I can't find any documentation,
FAQ, question, or other data on the topic. Thank you for any direction!
--
TimSlavin - 25 Mar 2010
You can have a conditional block spanning multiple lines. The only caveat is that your block may contain quotes, which confuses the tag parser. In that case you need to escape the quotes.
But the simplest example would be:
* Local City = Kansas
%IF{"$City='Kansas'" then="city is Kansas
* line 1
* line 2
* line 3
* line 4
"}%
... which renders as:
city is Kansas
- line 1
- line 2
- line 3
- line 4
If you want to show a block of text that may or may not contain quotes, you can use the INCLUDE macro:
%STARTSECTION{"quoted"}% This text contains "double quotes" and 'single quotes' %ENDSECTION{"quoted"}%
%IF{"$City='Kansas'" then="$percntINCLUDE{$quot$percntBASETOPIC$percnt$quot section=$quotquoted$quot}$percnt"}%
... which renders as:
This text contains "double quotes" and 'single quotes'
--
ArthurClemens - 28 Mar 2010
Thank you!
One quick follow up question: How do you handle OR operators within an IF statement? For example, to evaluate if a visitor is a member of two, three, or more groups and display the same content to those groups. Without an OR operator (or an AND operator), you would have to create identical IF statements then change the group name. Is there an OR operator?
UPDATE: I figured out the OR operator. It works if it separates single quote statements before the then statement, like this
%IF{"'guest' ingroup 'AdminGroup' or 'guest' ingroup 'CustomerGroup'" then=" ...
So that leaves my last question: do the IF statements test for logged in versus not logged in? For example, to display a login form if the visitor is not logged in and another message if they are? I can't find that in the documentation.
I appreciate all your help!
--
TimSlavin - 15 Apr 2010
IF supports the testing of context identifiers, one of which tells you if you are logged in. Check
IfStatements.
--
CrawfordCurrie - 15 Apr 2010