Software AG Products 10.7 | Integrating On-Premises and Cloud Applications | DSPs and building output templates | Using Output Templates to Format Service Output | %switch%
 
%switch%
You use the %switch% tag to process one block from a series of predefined alternatives based on the value of a specified variable at run time.
Syntax
%switch Variable%
%case ‘SwitchValue’%
Block of Code
%case ‘SwtichValue’%
Block of Code
.
.
.
[%case%
Default Block
of Code
]
%end%
Arguments
Variable specifies the name of the variable whose value will determine which case is processed at run time.
SwitchValue is a string that specifies the value that will cause the associated case to be processed at run time.
Effect on Scope
None
Notes
To select a case, SwitchValue must match the value of Variable exactly. SwitchValue is case sensitive—”FedEx” does not match “Fedex” or “FEDEX”.
The server evaluates %case% tags in the order that they appear in your code. When it finds a “true” case, it processes the associated block of code and then exits the %switch%…%end% structure.
You can specify a default case using the %case% tag without a SwitchValue. This case will be processed if Variable does not exist or if none of the other cases are true. The default case must appear as the last %case% in the %switch%…%end% structure.
For readability, you can optionally use %endswitch% instead of %end% to denote the end of the %switch% structure.
Examples
The following example inserts a specified paragraph, depending on the value in carrier.
.
.
.
%switch carrier%
%case ‘FedEx’%
<p>Shipped via Federal Express %value serviceLevel% %value trackNum%
%case ‘UPS’%
<p>Shipped via UPS %value serviceLevel%
%case ‘Freight’%
<p>Shipped via %transCompany%<br>
FOB: %value buyerInfo/streetAddr1%<br>
%value buyerInfo/streetAddr2%<br>
%value city%, %value state% %postalCode%
%end%
</p>
.
.
.
The following example invokes different services based on the value of a variable named action.
<HTML>
<HEAD>
<title>Order Tracking System</title>
</HEAD>
<BODY BGCOLOR="#FFFFCC">
<H1>Order Tracking System</H1>
<HR>
%switch action%
%case ‘shipinfo’%
%invoke orders:getShipInfo%
.
.
%case ‘showorder’%
%invoke orders:getOrderInfo%
.
.
%case ‘showinvoice’%
%invoke orders:getInvoices%
.
.
%end%
<HR>
%include stdFooter.txt%
</BODY>
</HTML>