Skip to main content
Windward

If and EndIf Tags

Overview

This is a high level overview explaining If Tag and Else Tag concepts.  For information on syntax and template samples see the If Tag reference.

 

File:Wiki/AutoTag/02AutoTag_Reference_Guide/03Tagging/001The_Windward_Reports_Tags/If_and_EndIf_Tags/if.png  If Tag

File:Wiki/AutoTag/02AutoTag_Reference_Guide/03Tagging/001The_Windward_Reports_Tags/If_and_EndIf_Tags/endif.png Else Tag

 

How the If and Else Tags work

The If Tag requires a Boolean statement to work. It uses the evaluation of True or False to print or not print the content between the If Tag and EndIf Tag.

 

This statement is used like a test  - like whether a node contains a value or not, whether the value is higher than $1000.00, or whether the value starts with the letter A.

 

  • If the statement evaluates to True, Windward will print whatever content (Tags or text) is present between the If Tag and its corresponding EndIf Tag. 
  • If the statement evaluates to False, Windward will not print the content between the If and EndIf Tags
    • When you want to switch between 2 options, use an Else tag. This way, if the statement evaluates as False, the content between the Else Tag and EndIf Tag will be printed instead. There is no need to include any select statement in the Else Tag. (If you need this approach with more than 2 options, take a look at the Switch and Case Tags

 

When you want a specific Tag to display something when some conditions are met, you will need to use an Out Tag with an IF Function as part of the select, or use Conditional Formatting.

The notEmpty Property

In the If Tag you can set the notEmpty property to true or false. This property is only used for a SQL select that returns null or an XPath select that returns a zero length string. For the case of returning a node that exists but is empty:

 

  • notEmpty = true - the If Tag will return false because the node must not be empty to return true.

  • notEmpty = false - the If Tag will return true because the node exists and you are not requiring it be non-empty.

If Tag Example

Suppose you want your report to display different things depending upon the data. For example, in a contact table, let's say we want the city name to be displayed only if the city is in North America. You can use the If Tag to do this.

 

Let's refer to a contact list table. The table below was made with a ForEach Loop and Out Tags to display contact names and city. Here's what the Output looks like without the If Tag:

I&EI01.png

 

Now let's say we want to display the city name only if the city is in North America.

 

First, you insert an If Tag that says, "See if the customer's city is in North America."

Second, you tell the report to display the city name if the condition is met.

 

This second step can be a bit tricky to understand, so let's reiterate. If the condition is met in part one ("See if the customer's city in is North America"), you have to explicitly tell the template what to do next: display the city name.

 

This may seem like an extra step, but it's a vital one – and it's one that gives the If Tag great flexibility and power. For example, you could tell the template that if the city is in North America to insert an image of the western hemisphere, to include a statement for residents in certain time zones, or to perform any number of actions.

 

The If Tag will continue to act (just like the ForEach tag continues to act) until it reaches an EndIf Tag.

 

Let's see this in action. Here's the table in our template before Output.  

There are three tags in the City column:

  • The If Tag sets the condition

  • The Out Tag tells the report what to do if the condition is met (i.e. display a piece of data)

  • The EndIf Tag tells the If Tag to stop

 

Note that the If Tag and EndIf tag are on either side of our Out Tag for the City, and are set within a ForEach Loop.

 

I&EI02.png

 

 

 

 

 

And here's the report:

I&EI03.png

 

Click for the If Tag Reference.

If Tag Notes and Tips

  • If you want to evaluate two conditions, then you need to Add a New Rule rather than incorporating it into the first condition box.
  • When creating the condition syntax, you need to precede with a = and use brackets eg. =(${cvs.STATUS}='-1') You can’t select the STATUS tag, which means you’ve got to be very careful when typing it in.
  • Before changing a conditional format, may be easiest to remove it completely and create it from scratch rather than trying to edit an existing conditional format.

Else Tag

The Else Tag adds increased power to the If Tag. By default, the If Tag has a third part that is understood but not explicitly stated:

 

  • If the condition isn't met, do nothing.

 

You can change this, however. If the If Tag's condition isn't met, you can tell the report template to do something else by using the Else Tag. For example, the report could insert the text "Outside North America" for cities outside the continent.

 

Here's the table with an Else Tag:

I&EI04.png

 

There are four tags in the city column:

 

  • The If Tag sets the condition

  • The Out Tag tells the report what to do if the condition is met

  • The Else Tag tells the report that if the condition set by the If Tag isn't met, to do something else: in this case, insert the text "Outside North America"

  • The EndIf Tag tells the template to stop setting a condition

 

Just as with the If Tag, the Else Tag has two parts:

 

  • Evaluating if a condition (set by the If Tag) isn't met.

  • Determining what to do if the condition isn't met.

 

And here's the final report:

I&EI05.png

 

Note: An Else Tag is optional, and it is used in conjunction with an If Tag. You can have an If Tag without an Else Tag, but you can't have an Else Tag without an If Tag.

 

 

  • Was this article helpful?