Overview
Conditional Output allows parts of content to be included in Generated Content and Terms based on a specific condition.
For example, you might want to:
- Only output a paragraph of text if a Keyword Term has a value,
- Output a heading if a Keyword Term contains a specific value.
Syntax
In any content based Content Group field, the following syntax can be used for Conditional Output:
@if(condition) Conditional Output Here @endif
@if
and end with @endif
. If either are missing, Conditional Output will fail.Extending this syntax, an optional else clause can be added:
@if(condition) Conditional Output Here when condition passes @else Conditional Output Here when condition fails @endif
Syntax can be placed on a single line if necessary (bolding to show syntax only):
@if(condition) Conditional Output Here when condition passes @else Conditional Output Here when condition fails @endif
Conditions
The following conditions are supported:
Condition | Comparison Operator | Syntax |
---|---|---|
Has Value | (none) | @if({keyword})…@endif |
Equals | == | @if({keyword} == value)…@endif |
Does Not Equal | != | @if({keyword} != value)…@endif |
Greater Than | > | @if({keyword} > value)…@endif |
Greater Than or Equal To | >= | @if({keyword} >= value)…@endif |
Less Than | < | @if({keyword} < value)…@endif |
Less Than or Equal To | <= | @if({keyword} <= value)…@endif |
Contains | LIKE | @if({keyword} LIKE value)…@endif |
Does Not Contain | NOT LIKE | @if({keyword} NOT LIKE value)…@endif |
Logical Operators
The following logical operators within an @if statement are supported:
Condition | Logical Operator | Syntax |
---|---|---|
AND | && | @if(condition1 && condition2)…@endif |
OR | || | @if(condition1 || condition2)…@endif |
For example, to only output some text when the Keyword {service} matches the value Web Design and the Keyword {location} matches the value Birmingham
@if({service} == Web Design && {location} == Birmingham) Conditional Output about Web Design in Birmingham would be displayed here. @endif
For example, to only output some text when the Keyword {service} matches the value Web Design or Web Development
@if({service} == Web Design || {service} == Web Development) Conditional Output about Web Design or Web Development would be displayed here. @endif
Examples
Output if Keyword contains a value
To only output some text when the Keyword {service} contains a value
@if({service}) Conditional Output about {service} would be displayed here. @endif
Output if Keyword matches a specific value
For example, to only output some text when the Keyword {service} matches the value Web Design
@if({service} == Web Design) Conditional Output about Web Design would be displayed here. @endif
Output based on Keyword containing a value, with a fallback if no value exists
For example, to output based on whether the Keyword {description} has a value or not
@if({description}) {description} @else A generic description to display when the Description keyword does not have a value @endif
Output if Keyword partially matches a specific value
For example, to only output some text when the Keyword {service} partially matches the value Web
@if({service} LIKE Web) Conditional Output about Web services would be displayed here. @endif
Output if Two Keywords match specific values
For example, to only output some text when the Keyword {service} matches the value Web Design and the Keyword {location} matches the value Birmingham
@if({service} == Web Design && {location} == Birmingham) Conditional Output about Web Design in Birmingham would be displayed here. @endif
Output if Keyword match any one of two values
For example, to only output some text when the Keyword {service} matches the value Web Design or Web Development
@if({service} == Web Design || {service} == Web Development) Conditional Output about Web Design or Web Development would be displayed here. @endif
Common Issues
Conditions are not honored
You may need to remove spaces between the value and comparison operator, particularly when working with Keyword columns.
For example:
@if({keyword(column)} != Hello) Keyword not Hello @else Keyword is Hello @endif
would be changed to:
@if({keyword(column)}!=Hello) Keyword not Hello @else Keyword is Hello @endif