Software AG Products 10.7 | Integrating On-Premises and Cloud Applications | DSPs and building output templates | Using Output Templates to Format Service Output | %ifvar%
 
%ifvar%
You use the %ifvar% tag to conditionally include or exclude a block of code based on the existence or value of a specified variable.
Syntax
%ifvar Variable [option option
option...]
%
Block of Code
[%else%
Block of Code]
%end%
Arguments
Variable specifies the name of the variable that determines whether or not the enclosed block of code is processed.
Options
You can use any of the following options with this tag. To specify multiple options, separate them with spaces.
Options
Description
-isnull
Includes the enclosed block of code only if Variable is null. For example: %ifvar backItems -isnull%.
-notempty
Includes the enclosed block of code only if Variable contains one or more characters (for string variables only). For example: %ifvar supplierInfo/email -notempty%.
equals(‘AnyString’)
Includes the enclosed block of code only if the value of Variable matches the string you specify in AnyString. (AnyString is case sensitive. “FedEx” does not match “Fedex” or “FEDEX”). For example: %ifvar carrier equals (‘FedEx’)%.
vequals(RefVar)
Includes the enclosed block of code only if the value of Variable matches the value of the variable you specify in RefVar. For example: %ifvar supplierInfo/state vequals(buyerInfo/state)%.
matches(‘regular_exp’)
Specifies that the condition is true if the value of Variable matches the regular expression regular_exp. For example: %ifvar carrier matches(‘UPS*’)%.
Effect on Scope
None
Notes
For readability, you can optionally use %endif% or %endifvar% instead of %end% to denote the end of the %ifvar% block.
Examples
The following example inserts a paragraph if a variable named AuthCode exists.
.
.
.
%ifvar AuthCode%
<p>Authorization Code Received %value $date%: %value AuthCode</p>
%endif%
.
.
.
The following example generates a line for each element in the backItems String list only if backItems exists; otherwise, it prints a standard message.
.
.
.
%ifvar backitems%
<p>The following items are backordered</p>
<p>
%loop backItems%
%value%<BR>
%endloop%
</p>
%else%
<p>There are no backordered items pending for your account</p>
%end%
.
.
.