Documentation >> Conditionals >> Advanced Features >> Negate Conditionals
Negate Conditionals
"Negating your conditionals" sounds scary, but it's not. It simply means "change the result to the opposite result". It's done with a single, special operator, the exclamation point: ! . However, when you're reading a conditional macro (or almost any programming/scripting code) and you see the "negation operator", just read it as if it said "NOT".
So, when the condition looks like, "! userIsMember", you'd read it as "NOT userIsMember". Obviously, then, this test would be satisfied if the person requesting the page is NOT a member of the site (or is not logged on, which means the same thing to Conversant).
Example
Without the "negation operator", how would you add something that should only be shown to guests (non-members), for example? Here's how you'd have to do it:
<!--#if condition="userIsMember"-->
0. No text here.
<!--#else-->
1. This text will only be shown to your guests, perhaps explaining the benefits of becoming a member.
<!--#endif-->
However, with the "negation operator" ("NOT"), you only need to do this:
<!--#if condition="! userIsMember"-->
1. This text will only be shown to your guests, perhaps explaining the benefits of becoming a member.
<!--#endIf-->
Here's the above example, put into action:
1. This text will only be shown to your guests, perhaps explaining the benefits of becoming a member.
If you're logged in, then line #1 isn't there. If you log out and come back to this page (and reload it if necessary), then line #1 will be right above this line.
Using ! With Complex Conditionals
The "!" (negation operator) can also be used in complex conditionals. Here's an example:
<!--#if condition="userIsMember && ! userIsConvAdmin"-->
1. This text will only be shown to members (logged on) that are NOT administrators of this site.
<!--#endIf-->
... and the above example put to use:
If you're logged in but not an admin for this site, then you can see line #1 above. If you're not logged in, or you are an admin, then you don't see anything at all.
In a complex conditional, you can negate none, any, or all of the conditions.
Using The Negation Operator With Grouped Conditionals
Read about this subject in the docs for grouped conditionals.
View in DG
|