The mgiIf Tag
Tag Behavior
The mgiIf tag performs a conditional comparison and displays
a result based upon the outcome of the comparison.
Note: Due to customer requests, the mgiConditional
tag was created as a complete if, then, else comparison solution.
The mgiConditional and mgiIf tags perform the same function,
but the mgiConditional tag has a simpler, more complete structure.
We recommend that you use the mgiConditional tag rather than
the mgiIf or mgiInlineIf tags.
Tag Syntax
The mgiIf tag has a beginning tag with one required parameter
and no optional parameters for all targets, a body, an optional
mgiElse tag in the body, and an ending tag. In addition, the
mgiIf tag has required and optional parameters for specific targets.
The tag form is:
<mgiIf target="Target" targetParameter="Value">
Body Value 1 - Text, HTML, or MGI Tags
<mgiElse>
Body Value 2 - Text, HTML, or MGI Tags
</mgiIf>
Required Parameters for all Targets:
- target="Target" where "Target"
is the object of the conditional comparison. Valid targets include
the following. See the specific required
and optional parameters for each target type below.
- "Browser" - the Browser target is a comparison
with the browser string in the HTTP request (1
required, 1 optional parameter).
- "Client" - the Client target is a comparison
with the client IP number or domain name in the HTTP request
(1 required parameter).
- "Cookie" - the Cookie target is a comparison
with the value of a specified cookie (1
required, 1 optional parameter).
- "Date" - the Date target is a comparison
with current GMT weekday, month, day, or year (4
optional parameters).
- "Field" - the Field target is a comparison
with the value of a posted form field submission (2
required, 1 optional parameters).
- "PostArgument" - the PostArgument target
is a comparison with the value of a posted form field submission
(2 required, 1 optional parameters).
- "Referrer" - the Referrer target is a comparison
with the complete or partial referral URL (1
required, 1 optional parameter).
- "Variable" - the Variable target is a comparison
with the value of a specified variable (2
required, 2 optional parameter).
Tag Bodies:
- Body Value 1 - If the conditional comparison is true,
the text, HTML, and tags between the beginning mgiIf tag and
the mgiElse tag is displayed. If no mgiElse tag is present, then
the text between the beginning and ending mgiIf tag is displayed
when the conditional comparison is true.
- Body Value 2 - If the conditional comparison is false,
the text, HTML, and tags between the mgiElse tag and the ending
mgiIf tag is displayed. If no mgiElse tag is present, then nothing
is displayed.
Browser Target Parameters:
Required
- contains="String" where "String"
is any portion of the comparison browser HTTP request (e.g. "Mozilla"
for Netscape browsers, "IE" for Internet Explorer browsers,
"3.0" for version 3 browsers, etc.).
Optional
- case-sensitive="Yes" or "No" where
"Yes" indicates that the comparison string must match
the case of the HTTP browser and "No" indicates that
the comparison string is not required to match the case of the
HTTP browser. The default is "No".
Client Target Parameters:
Required
- value="IPorDN" where "IPorDN"
is the comparison IP address or client domain address. Wildcard
comparisons can be achieved with an asterisk (*). For example,
*.domainA.com will match all clients from domainA.com and 205.152.*.*
will match all clients from the 205.152 LAN. (Note: to complete
a domain comparison, domain lookups must be enabled on the server.)
Cookie Target Parameters:
Required
- name="Name" where "Name" is the
name of the comparison cookie.
- value="Value" where "Value" is
the value to compare with the value of the cookie.
Optional
- relationship="Comparison Type" where "Comparison
Type" is the type of comparison to perform between the cookie
value and the value parameter. Comparison Types include "equalTo",
"notEqualTo", "contains", "beginsWith"
and "endsWith". The default relationship is "equalTo".
All comparison types are case-sensitive.
Date Target Parameters:
Optional
- weekday="Day" where "Day" is the
full or abbreviated text week day comparison (e.g. "Tuesday"
or "Tues").
- month="Month" where "Month" is
the full text, abbreviated text, numeric month or padded numeric
month comparison (e.g. "March", "Mar", "3",
or "03").
- day="Integer" where "Integer"
is the numeric day of the month or padded numeric day of the
month comparison (e.g. "9" or "09").
- year="Integer" where "Integer"
is the four-digit or two-digit year comparison (e.g. "1999"
or "99").
Field Target and Post Argument Target Parameters:
Required
- name="Name" where "Name" is the
name of the comparison form field or posted argument.
- value="Value" where "Value" is
the value to compare with the value of the form field or posted
argument. For the relationship "isEmpty",
the value parameter is not required.
Optional
- relationship="Comparison Type" where "Comparison
Type" is the type of comparison to perform between the form
field/post argument value and the value parameter. Comparison
Types include "equalTo", "notEqualTo", "contains",
"beginsWith", "endsWith", "isEmpty",
"lessThan", "greaterThan", "lessThanOrEqualTo"
and "greaterThanOrEqualTo". The default relationship
is "equalTo". All comparison types are case-sensitive.
The four less than and greater than comparison types function
only if the value of the form field or post argument is a number.
If the value is not a number, then "False" will be
displayed.
Referrer Target Parameters:
Required
- value="String" where "String"
is any portion of the comparison referral URL.
Optional
- match="Exact" or "Partial" where
"Exact" performs an exact comparison with the referral
URL and "Partial" will match any portion of the referral
URL. The default match is "Exact".
Variable Target Parameters:
Required
- name="Name" where "Name" is the
name of the comparison variable.
- value="Value" where "Value" is
the value to compare with the value of the variable. For
the relationship "isEmpty", the value parameter is
not required.
Optional
- relationship="Comparison Type" where "Comparison
Type" is the type of comparison to perform between the form
variable value and the value parameter. Comparison Types include
"equalTo", "notEqualTo", "contains",
"beginsWith", "endsWith", "isEmpty",
"lessThan", "greaterThan", "lessThanOrEqualTo"
and "greaterThanOrEqualTo". The default relationship
is "equalTo". All comparison types are case-sensitive.
The four less than and greater than comparison types function
only with page variables or site variables that are a "Number"
type. The tag auto-detects the type of variable.
- scope="Page" or "Site" where "Page"
indicates that the variable was set as a temporary page variable
and where "Site" indicates that the variable was set
as a permanent site variable. The default scope is "Page".
Example Usage and Output
<mgiIf target="variable" name="score"
relationship="greaterThanOrEqualTo" value="11" scope="Site">
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 target="variable" name="score"
relationship="greaterThanOrEqualTo" value="6" scope="Site">
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 5 quiz questions has been created.
The value of each quiz answer is a number. On the "return"
page of the form, an mgiMath tag is used to calculate the sum
of all 5 questions dynamically. The sum is then set in a site
variable. Nested mgiIf tags display text based on the total quiz
score in the variable.
If a visitor's score is greater than or equal to 11, then
the following text will be displayed:
- 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 be displayed:
- 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 to5, then the
following text will be displayed:
- 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
- Quizzes
|