JEXL Context Expressions

The Context Expressions you attach to Target Groups must be valid boolean JEXL (Java Expression Language) expressions.

Context Expression syntax

For the standard JEXL expression syntax, see the Apache Commons website.

In addition to standard JEXL syntax, the SDL Context Engine expects all Context Expressions to be stated according to the following pattern:

[aspectName].[propertyName]

where:

  • aspectName is one of the following: browser, device or os
  • propertyName is one of the supported properties for the aspect

For complete details on the existing Context Expressions aspects and their properties, see the SDL Tridion Sites documentation.

Context Expressions examples

The DXA Context Expressions module includes the following example Target Groups with attached JEXL Context Expressions:

Target Group nameContext Expression
cx.isChromebrowser.model == 'Chrome'
cx.isMobiledevice.mobile == 'true'
cx.isAppledevice.vendor == 'Apple'
cx.isAndroidos.model == 'Android'

You can use these samples and create your own Target Groups with Context Expressions, as needed.

Versions and version comparison

You can also create Context Expressions for versions of other aspects, such as specific versions of the browser, device, or operating system. For example:

browser.version > 6.0

You can combine them with other expressions, such as in the following examples:

browser.model == 'Chrome' && browser.version > 6.0

For version comparison, use the > operator as a version comparison and not a string or numerical comparison. For example:

os.version > 4.0
Alternatively, the > can be replaced by gt to allow for easier inclusion in XML files. For example:
os.version gt 4.0