The #if directive in FML allows for text to be included when the web page is generated, on the condition that the if statement is true. For example:
|
#if($Values.get('Our Sales').Result <
1000 ) |
In this case, if Our Sales is less than 1000, the output will be:
|
Sales have fallen below 1000! |
Conversely, if Our Sales is equal to or greater than 1000, the statement evaluates as false, and there is no output.
The variable is evaluated to determine whether it is true, which will happen under one of two circumstances:
the variable is a boolean (true/false) which has a true value, or
the value is not null.
The content following the #if directive becomes the output if the evaluation is true.
An #elseif or #else directive can be used with an #if directive.
Forio Macro Language will stop at the first expression that is found to be true.
In the following example, suppose that your model's EndStep has a value of 15 and it's SimStep has a value of 6.
|
#if($Run.EndStep < 10 ) |
In this example, if $Run.EndStep is greater than or equal to 10, FML makes the output of the if statement Go East. If $Run.EndStep has a value of 10 and $Run.SimStep had a value of 7, then $Run.EndStep is neither greater than 10 nor equal to 10, and $Run.SimStep is not equal to 6. All if and #elseif statements are false, so the output is "Go West".
The #if directive can also be used to see if a reference is defined. For example, the following FML checks to see if the user is currently doing a trial run of the simulation. The reference $Trial is only defined if a trial is currently in progress.
|
#if($Trial) |
FML uses the equivalent operator to determine the relationships between variables. Here is a simple example to illustrate how the equivalent operator is used.
|
#set ($foo = "black")
|
FML supports standard logical operators, allowing you to compare numbers or strings. Logical operators have a symbol but can also be spelled out explicitly. This allows you to use the operators in XML documents where some of the symbols (for example '>') are banned.
|
Operator Name |
Symbol |
Alternative Symbol |
Example |
|
Equals Number |
== |
eq |
#if( $foo == 42 ) |
| Equals String |
== |
eq |
#if( $foo == "bar" ) |
| Object Equivalence |
== |
eq |
#if( $foo == $bar ) |
| Not Equals |
!= |
ne |
#if( $foo != $bar ) |
| Greater Than |
> |
gt |
#if( $foo > 42 ) |
| Less Than |
< |
lt |
#if( $foo < 42 ) |
| Greater Than or Equal To |
>= |
ge |
#if( $foo >= 42 ) |
| Less Than or Equal To |
<= |
le |
#if( $foo <= 42 ) |
| Boolean NOT |
! |
not |
#if( !$foo ) |
Note that in most cases you will be comparing a model result to a number. Be sure to use the Result property in order to compare the actual result. The first example below will not work. The second example properly uses the Result property and will correctly check the value.
|
#if($Values.get("Sales") == 0)
#if($Values.get("Sales").Result == 0) |
You can also use the getResult() method to compare a number to a past result.
|
#set($lastStep = $Run.SimStep - 1)
|
You can use AND, OR, and NOT operators between expressions within the #if directive. Each operator has a standard symbol and a spelled-out alternative.
For example:
|
#set ($first = 5) #if($first == 7 || $second == 12) #if($third != 15) #if(!$fourth)
|
The AND operator uses two ampersands: &&. You can also use the word "and".
AND returns TRUE if both arguments are TRUE; returns FALSE if one or more arguments is FALSE.
Example:
|
|
The OR operator uses two bars: ||. You can also use the word "or".
OR returns TRUE if any argument is TRUE; returns FALSE if all arguments are FALSE.
Example:
|
|
The NOT operator uses an exclamation: !. You can also use the word "not".
NOT reverses the value of its argument. Use NOT when you want to make sure a value is not equal to one particular value.
Example 1:
|
|
Example 2:
|
|
You can also type the words true and false directly in FML and Broadcast will interpret them correctly. false returns the logical value for FALSE and true returns the logical for TRUE.
Note: false and true must always be all lower-case.
Example 1:
|
|
Example 2:
|
|