Documentation >> Conditionals >> Advanced Features >> Combining Conditional Macros
Complex Conditional Macros
We've already looked at Nesting Conditional Macros, which allows you to have multiple "conditions" satisfied (tests performed) before some text is added to your page. Complex conditional macros offer another way of doing the same thing by combining multiple conditions in a single statement. This makes it easy to do some things that are very difficult or impossible to do with nested conditionals alone.
Using a "complex conditional" means that you're using more than one test in the same if (or elseif) macro, and you've separated those tests with one of the special operators called boolean AND or boolean OR.
See examples of these special operators in use, at the bottom of the page.
The boolean AND operator is written like this: && .
This operator tells Conversant that "if the tests on both sides of the && are true, then the result is true. If either or both of the tests are false, then the result is false." In other words, both sets of tests must be satisfied, or it will be false. Consider this example:
<!--#if condition="requestIsReply && userIsConvAdmin"-->
Some text that site admins will see on reply pages.
<!--#endif-->
When this #if macro is being evaluated, Conversant understans the && to mean that both tests must be true. Here's what it does with that information:
- Test the first condition: is the page a message-reply page in the discussion group?
- If not, then there is no need to test the second condition, because one of them is already false. So, the block of text under the "if" is skipped.
- Otherwise, test the second condition: is the current user an admin for this site?
- If not, then skip whatever is under the #if.
- Otherwise, both tests were true, so it will use the text under the "if".
(Note: when we refer to text that is "under' a conditional macro, we're simply referring to any text between that conditional macro and the next one.)
The boolean OR operator is written like this: || . Those are two vertical "pipe" characters, which are usually typed with shift- (shift backslash) on American keyboards.
This operator tells Conversant that "if either of the tests on the sides of the || are true, then the result is true. If both of the tests are false, then the result is false." In other words, only one of the tests must be satisfied. Consider this example:
<!--#if condition="requestIsReply || userIsConvAdmin"-->
Some text that will show to site admins, or to anyone looking at a message's reply form..
<!--#endif-->
When this #if macro is being evaluated, Conversant understans the || to mean that only one of the tests must be true. Here's what it does with that information:
- Test the first condition: is the page a message-reply page in the discussion group?
- If it is, then there is no need to test the second condition, because one of them is already true. So, the block of text under the "if" is used.
- Otherwise (the first test failed), test the second condition: is the current user an admin for this site?
- If not, then skip whatever is under the #if, because both tests failed.
- Otherwise, the second test passed - which is all that's needed - so it will use the text under the "if".
(Note: when we refer to text that is "under' a conditional macro, we're simply referring to any text between that conditional macro and the next one.)
Here's an example that uses both && and || .
<!--#if condition="requestPageType=='Bound Message' || username=='[email protected]'"-->
1. You'll only see this if you're looking at this page in the docs, OR (on any page that it's been used) if you're logged in as Joe Bluejeans.
<!--#elseif condition="requestPageType=='Message' && userIsMember"-->
2. You'll see this if you're looking at the message in the discussion group, AND if you are a member of this site (the specific username won't matter as long as you're logged in).
<!--#endif-->
Now here's the above code in action. To see the different results, switch back and forth between this page in the docs, and the message in the discussion group that was used to created it. Also, look at the pages while you're logged off, and again while you're logged on.
1. You'll only see this if you're looking at this page in the docs, OR (on any page that it's been used) if you're logged in as Joe Bluejeans.
View in DG
|