The mgiIf Tag

Tag Behavior

Use the mgiIf tag to perform a conditional comparison and display a result based upon the outcome of the comparison (see also mgiInlineIf and mgiSwitch).


Tag Syntax

The mgiIf tag has two forms. The mgiIf tag can be used as a beginning tag with three required parameters and two optional parameters, a "true" body, an mgiElse tag, a "false" body, and an ending mgiIf tag OR as a beginning tag with three required parameters and two optional parameters, a "true" body, and an ending tag. The tag forms are:

<mgiIf lhs="Comparison Value" relationship="Relationship" 
rhs="Comparison Value" order="Order" 
caseSensitive="Yes/No">
Value if comparison is true
<mgiElse>
Value if comparison is false
</mgiIf>

and

<mgiIf lhs="Comparison Value" relationship="Relationship" 
rhs="Comparison Value" order="Order" 
caseSensitive="Yes/No">
Value if comparison is true
</mgiIf>

Required Parameters:

  • lhs - The lhs is the first value tested in the conditional comparison (i.e., the "left hand side" of the comparison). The lhs value must be a number for the greaterThan, greaterThanOrEqualTo, lessThan, and lessThanOrEqualTo relationships. In order to use special reserved characters such as tabs, backslashes, and ASCII characters, you must use the appropriate Escaped String format.
  • relationship - The relationship is the type of comparison to perform. You may use the relationship name or symbol. Valid relationships include:
    • lessThan (<)
    • lessThanOrEqualTo (<=)
    • greaterThan (>)
    • greaterThanOrEqualTo (>=)
    • equals (=)
    • doesNotEqual (<>)
    • contains
    • doesNotContain
    • beginsWith
    • doesNotBeginWith
    • endsWith
    • doesNotEndWith
    • isEmpty - The rhs parameter is not required for this relationship.
    • isNotEmpty - The rhs parameter is not required for this relationship.
  • rhs - The rhs is the second value tested in the conditional comparison (i.e., the "right hand side" of the comparison). In order to use special reserved characters such as tabs, backslashes, and ASCII characters, you must use the appropriate Escaped String format.

Optional Parameters:

  • order - The order determines the order of values in the conditional comparison. If the order parameter value is "alphabetical", then values are compared alphabetically as ascii strings (i.e., characters appear alphabetically in the order of non-printable characters, punctuation, numbers, capital letters, and lower-case letters). Therefore, if two numbers are compared alphabetically as strings, they are ordered from left to right alphabetically (e.g., "550" appears alphabetically before "60"). If the order parameter value is "numerical", then number values are compared numerically from the decimal. If either value is not a number in a numerical order, then the values are compared alphabetically as strings. The default value is "numerical".
  • caseSensitive - The caseSensitive parameter specifies whether the lhs and rhs values are checked for case-sensitivity. If the caseSensitive parameter value is "Yes", the lhs and rhs values are checked for case-sensitivity. If the caseSensitive parameter values is "No", the lhs and rhs values are not checked for case-sensitivity. The default value is "No".


Example Usage and Output

<mgiIf lhs={mgiGet name="Score"} 
relationship="greaterThanOrEqualTo" rhs="11">

Your quiz score indicates that you are a Growth Investor.
Growth Investors are willing to take risks and prefer short
term gain to long term gain.

<mgiElse>

<mgiIf lhs={mgiGet name="Score"} 
relationship="greaterThanOrEqualTo" rhs="7">

Your quiz score indicates that you are a Moderate Investor.
Moderate Investors will take well-researched risks and can
handle fluctuations in the market.

<mgiElse>

Your quiz score indicates that you are a Conservative Investor.
Conservative Investors prefer minimal risk options and growth 
over a long term.

</mgiIf>

</mgiIf>

In this example, a form with quiz questions has been created. The value of each quiz answer is a number. On the processing page of the form, an mgiMath tag is used to calculate the sum of all 5 questions and that value is set in a page variable named "Score". The variable value is then compared to the values in the "rhs" parameters and the result of the conditional comparison displays.

If a visitor's score is greater than or equal to 11, then the following text will display:

Your quiz score indicates that you are a Growth Investor. Growth Investors are willing to take risks and prefer short term gain to long term gain.

If a visitor's score is greater than or equal to 7, then the following text will display:

Your quiz score indicates that you are a Moderate Investor. Moderate Investors will take well-researched risks and can handle fluctuations in the market.

If a visitor's score is greater than or equal to 5, than the following text will display:

Your quiz score indicates that you are a Conservative Investor. Conservative Investors prefer minimal risk options and growth over a long term.


Suggested Usage

  • Conditional Comparisons


[Understanding MGI Menu] [Using MGI Menu] [Referencing MGI Menu]


[MGI Guides Main Menu] [User Guide Main Menu]