Free-Conversant Support / Conditional Macros
 Home   About Conversant   Free Sites   Hosting   Support   XML-RPC 

Search




Conditional Macros

Before you try to use conditional macros, you need to understand the basic syntax of Conversant's macros (how they're written). See the top of the Simple Macro docs page.

Conditional macros allow you more extensive control over the output of your pages based on current rendering conditions. They're tests, or "conditions". If the test is passed (referred to as "returning true"), then the text and macros enclosed by that condition is used. If the test fails, then the next test is checked, and so on until a test is passed or the end of the conditionals are reached.

The names of the conditional macros are: if, elseIf, else, and endIf.

They're used like this:

1. This text will always be displayed, because it's before the #if macro.

<!--#if condition="userIsMember"-->

2. This text is displayed if you're logged in.

<!--#else-->

3. This text is shown only to guests (anyone who's not a member or hasn't logged in).

<!--#endIf-->

4. This text will always be displayed, becuase it's after the #endIf macro.

Understanding this example should be pretty simple. The name of the macros used here were "if", "else", and "endif". In the "if" macro, the condition parameter specifies the test that will be run. If the person visiting the page is a member that has "logged in" to the site, then the test has "returned true", and he'll see lines 1, 2, and 4. If the person isn't a member, or hasn't logged on yet, then the test "returns false", and he'll see lines 1, 3, and 4.

Now here's the same set of macros, in action:

1. This text will always be displayed, because it's before the #if macro.

3. This text is shown only to guests (anyone who's not a member or hasn't logged in).

4. This text will always be displayed, becuase it's after the #endIf macro.

If you're a member of this site, and you've logged in, then you can see lines 1, 2, and 4. If you're not yet a member, or you haven't logged on, then you see line 3 instead of line 2. Understand? Log on or off of the site, then come back here and you'll see the other line, which might help you understand what's happening.

Note: if you aren't a member, you can sign up for free.

See the rest of the docs for more information on conditional macros. If you have any questions, please ask them here on the support site (requires free membership).

View in DG


This site managed with Conversant, © Copyright 2009 Macrobyte Resources