Generate: Conditional Output

Overview

Conditional Output is available in Page Generator Pro 3.2.7 and higher, releasing Thursday June 17th 2021 23:59 UTC.

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
Syntax must start with @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
It’s best to write Conditional Output in plain text (i.e. not a Visual Editor or Rich Text / Content based Page Builder block). This avoids Page Builders wrongly wrapping/adding its own tags within Conditional Output, which will result in invalid layout and/or no/invalid parsing of conditions.
Nesting @if statements are not supported.

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
value is case sensitive, except for LIKE and NOT LIKE comparison operators.
The Keyword’s Term must be plain text.  Using comparison operators against a Keyword Term that contains HTML will not work.

Logical Operators

Support for Logical Operators is available in Page Generator Pro 4.4.3 and higher, releasing Thursday November 2nd 2023 23:59 UTC.

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
Use of both && and || logical operators within a single @if statement are not supported.

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