Structuring Conditionals in XML
S-Tag conditionals allow you to display dynamic content using sophisticated constructs. This topic shows you how to construct conditionals in XML. For information on adding conditionals using Standard Bracket Input, see Structuring Conditionals with Standard Bracket Input.
The following code sample demonstrates an "If ... else if ... else if ... else" construct:
<convio:choose><convio:when ID="whatsontv" title="Affiliate" test="eq"><convio:op>PR_</convio:op><convio:op><convio:session title="AffiliateSessionVar" name="80" param="Affiliate"></convio:session></convio:op><convio:then>What's On TV?</convio:then></convio:when> <convio:when title="events" test="eq"><convio:op>evt_</convio:op><convio:op><convio:session title="AffiliateSessionVar" name="80" param="Affiliate"></convio:session></convio:op><convio:then>Events</convio:then></convio:when>
<convio:when title="events" test="eq"><convio:op>2</convio:op><convio:op><convio:session title="CurrentApp" name="4"></convio:session></convio:op><convio:then>Events</convio:then></convio:when> <convio:otherwise title="Unknown">Default Affiliate</convio:otherwise></convio:choose>
If the session variable, Affiliate, is PR_
, then What's On TV? displays and the choose completes. If, however, the first condition is not successful (if Affiliate is not PR_
), the session variable, Affiliate, is checked for the value of evt_
. If Affiliate is evt_
, then the word, Events, displays. If the current application has an ID of 2 (Calendar), then the word, Event, displays. If none of these matches, the Default Affiliate displays.
Convio Tag Components
<convio:choose></convio:choose>
Contains all the conditions and default "otherwise" content.
<convio:when></convio:when>
Contains a condition and the content to render if that condition is successful. Success is selected using the case="" attribute:
case="true"
This condition will be successful if it evaluates as true. This is the default behavior if no case="" attribute is present.
case="false"
This condition will be successful if it evaluates as false.
The type of comparison is determined by the value of test="":
test="empty"
This will be true if the value is empty. Requires only one <convio:op></convio:op>
element.
test="nempty"
This will be true if the value is not empty. Requires only one <convio:op></convio:op>
element.
test="eq"
This will be true if the values match. Requires two <convio:op></convio:op>
elements.
test="neq"
This will be true if the values do not match. Requires two <convio:op></convio:op>
elements.
test="contains"
This will be true if the second value can be found some where in the first value. Requires two <convio:op></convio:op>
elements.
test="ncontains"
This will be true if the second value cannot be found somewhere in the first value. Requires two <convio:op></convio:op>
elements.
<convio:op></convio:op>
Contains a value to be compared. This may be text, HTML, or other <convio> / [[Xn]]
tags.
<convio:then></convio:then>
Contains text to be rendered. This may be text, HTML, or other <convio> / [[Xn]]
tags.
<convio:otherwise></convio:otherwise>
Contains the default text to be rendered if none of the <convio:when>
elements are successful. This may be text, HTML, or other <convio> / [[Xn]]
tags.