Appendix: Using the ISDATATRUE/ISNOTDATATRUE Element Tags
The ISDATATRUE and ISNOTDATATRUE elements will hide a block of content unless a specific expression evaluates to True or False respectively. This can test the result of a JSON query, for example by counting the number of items in a JSON array, or checking whether a JSON item has a specific value.
Implementation:
- Click to open the Element Browser to the right of the window.
- Use the Filter menu to select Tags.
- Locate and select ISDATATRUE or ISNOTDATATRUE.
These elements use the following syntax:
<%= ISDATATRUE( Keyword Path Name Type Expression) %> Affected content goes here <%= %>
Parameters can be entered in any order. Where a parameter is not required, it should be excluded.
All parameters are required:
Parameter | Description |
---|---|
Keyword | The keyword of the intended JSON object. |
Path | The path of the intended item. |
Name | A user-defined alias for the path of the intended item. This alias should be referenced by the Expression parameter, so its value can be used when the expression is evaluated. The default value is JSONDataValue. |
Expression | An expression that will be evaluated when the element is processed. Including Name's value in the expression will cause the item at the associated path to be evaluated according to the element's Type. The expression must return True for the content inside the element to be rendered. |
Type | The expected type of data at the specified Path. If this parameter is set to "Count", Name will return the number of items in an array. Other terms will cause it to return the value after converting it to the type specified, applying suitable formatting where possible. The additional terms are: "Boolean", "Currency", "Date", "DateTime", "Number", "String", or "Time". |
The following example shows an ISDATATRUE element that counts the number of items in an array (BasketContents). If the result is zero, the element displays a message indicating the basket is empty:
<%= ISDATATRUE( Keyword="CustomerBasket" Path="BasketContents" Name="BasketItemCount" Type="Count" Expression="BasketItemCount=0;") %> <p>The basket is empty.</p> <%= %>
Alternatively, if the number of items in the basket is not zero, the expression will evaluate as False and the message will not be displayed.
If you want to get the opposite result, so that a message is displayed if the data does not evaluate to True, you would simply use the ISNOTDATATRUE element instead:
<%= ISNOTDATATRUE( Keyword="CustomerBasket" Path="BasketContents" Name="BasketItemCount" Type="Count" Expression="BasketItemCount=0;") %> <p>Your basket contains items.</p> <%= %>