Skip to main content

Logic Tag Changes in Tag Processor 2

In addition to increased functionality with ForEach and Expansion Tags, we’ve also made enhancements to Logic Tags (If, Else) Tags in TP2. We’ve added 3 categories to the “Order” attribute of the If Tag that will give the user more control over their template design and enable them to achieve more than ever before. The 3 new categories for If Tags are “Content”, “Row” and “Block”.

Content Logic Tags

When the “Order” attribute is set to “Content”, If and Else Tags behave just like before. This means that it will hide any content between the If and Else Tags, or Else and End-If Tags, based on if the condition is true or false. This type can be used inside or outside of tables. That means, in a table it will hide cells sequentially and can alter the structure of the table. For instance, below the If Tag evaluates to “true”, so the portion between the Else Tag and the End-If Tag are hidden in output:

While this can serve its purpose, adding the “Row” and “Block” types now give the user much more power with logic in tables.

Row Logic Tags

One of the new “Order” attributes is “Row”. Setting this will cause entire rows to be hidden, based on the conditions set. This type is very useful when you have a ForEach in a table and may need to hide or show different rows depending on which data the ForEach Tag is currently pointing at.

The way “Row” order works is the rows between the If and the Else Tags (not including the row of the Else Tag) belong to the If Tag portion and the rows between the Else Tag and the End-If (including the row of the End-If) are including in the Else Tag portion. If there is no Else Tag, its just the rows between the If and End-If Tags (inclusive). Below are a couple of examples with cells being marked to which portion they belong to:

There are 2 restrictions with the “Row” type If Tags.

  1. These can only be used inside of tables.
    1. If you try to use an If Tag with the “Order” set to “Row” outside of a table, you will get an exception explaining this. Thise also includes other If Tags in the group (i.e. Else and End If Tags)
  2. The tags must be placed in the first column of the row.
    1. If you place the If, Else or End-If tags in any other column when “Order” is set to “Row”, you will get an exception explaining this.

As helpful as it is to hide rows, sometimes you need to hide a portion of the table without compromising the integrity of the table’s design. This is where “Block” type If Tags come into play.

Block Logic Tags

The final new type of If Tag is the “Block” order If Tag. This type is the most complex, but the most powerful. This type of If tag most resembles the Column Expansion tag in behavior and is best used in combination with Column expansions, although it can be used effectively in many more scenarios. The principal behind the “Block” If Tag is defining a portion of the table (a block) that will be removed (or kept) and not impact other content in rows and cells after it. While this may sound confusing the examples below will help demonstrate what this means.

To create the block, place the If Tag where you would like the block to start, and then place an End-If tag at where you would like the block to end. This will essentially create a rectangle of cells that will be kept or hidden based on the evaluation of the If Tag. Below is a table where the highlighted cells are contained in the Block.

If the tag is false, the cells in that come in columns after the If-Block will be shifted over and empty padding cells will be inserted so the table can maintain structure. Below is the example output.

As you can see this is helpful as you can hide sub portions of the table without having other cells getting completely shifted out of position and ruining the structural integrity of rows. To make this more powerful, this can be used in combination with Else Tags so you can create a scenario where either section is shown. Below is a table showing how the structure works.

info

The Else Tag must be placed in the same row as the If Tag. If it is not, an exception will be thrown explaining this.

Here would be the two outcomes:

If Tag evaluates to “true”:

If Tag evaluates to “false”:

As mentioned above, these work really well with Column Expansions and can help hide or show different columns in the expansion based on the current data of the expansion loop.

While Block type If Tags are very powerful there are a couple of restrictions to them:

  1. These can only be used inside of tables.
    1. If you try to use an If Tag with the “Order” set to “Row” outside of a table, you will get an exception explaining this. Thise also includes other If Tags in the group (i.e. Else and End If Tags)
  2. The If and Else tags must be placed in the same row
    1. If this isn’t followed, an exception will be thrown explaining this.

With all of these changes to If Tags, the user has more power and control than ever with logic in tables.