Conditions

Last Updated: Aug 13, 2019
documentation for the dotCMS Content Management System

A dotCMS Rule is composed of Conditions and resulting Actions that take place if the Conditions evaluate to be TRUE. Conditions make up the WHEN triggers of the dotCMS Rule; Actions comprise the THEN portion of the Rule logic. Many Conditions may be set on a Rule, and may be joined together using logical operations (And, Or, and Not). Actions will only execute if the ending result of the Condition logic is TRUE.

There are many pre-set Condition Types to choose from. Please see the Condition Types documentation for an explanation of the behavior and properties of each Condition type.

Condition Groups

Each Condition is part of a Condition Group, and when you create a rule the first Condition Group is created by default. Additional Condition Groups can be added to a Rule by clicking the plus sign (+), at the right side of the GREY Rule bar. An AND/OR operator will immediately appear to the left hand side of secondary Condition Groups to help define their logical relationship to the Condition Group immediately above.

Multiple Conditions can be added inside of each Condition Group by clicking the GREEN plus sign (+), to the right of an existing Condition. Appending new Conditions to an existing Condition, creates a logical relationship between the two Conditions. The AND/OR operator can be clicked to toggle its value and define the logical relationship of the each Condition to the Condition immediately above it. Condition Groups and Conditions, all link together in a logical series using AND/OR comparitors whose cumulative logical result must be TRUE to fire the Action(s) for a particular Rule.


In the example above, four Conditions are being set. One Condition, within first Condition Group checks to see if the Visitor has visited the “/services/retirees” page. However, because of the “AND” operator between the first and second Condition Group, the a SECOND Condition Group must ALSO result to be true for the Rule Actions to execute.

The second Condition Group checks the Visitor's country. If the Visitor is browsing from the US, UK, OR Canada, then the second Condition Group will also result to be TRUE.

If the first AND second Condition Groups result in TRUE, then the Visitor's Persona is set to “Retiree” and the Session Attribute “language” is set to “en” for English.

Operator Precedence

Logical operators in Conditions are evaluated using standard programming operator precedence conventions. Logical AND (&&) statements take precedence over logical OR (||) statements at the same level because they have a higher precedence.

The sum evaluation of all the Conditions for a Rule, will result in a Boolean, or TRUE/FALSE value. If the Rule Conditions evaluation results in a TRUE value, then the Rule Actions occur. The order of either Condition Groups or Conditions also determines precedence. Conditions that appear first (at the top) in the Rule or Condition Group, will have precedence and be evaluated first.

When planning the order of placement of Rule Conditions, it may be helpful to write a logical statement before adding the Rule Conditions, to ensure the conditions are evaluated in the order you intend. For example:

if ((Condition_A) || (Condition_B && Condition_C) && (Condition_D || Condition_E))

Logical Short-Circuits

The AND (&&) and OR (||) operators perform short-circuit evaluation (do not evaluate the second operand if the result is known after evaluating the first), therefore it is advantageous to place the lightest (least processing overhead) evaluation Conditions first, and the heaviest evaluation Conditions last. In the logical statement above, “Condition_E” and/or “Condition_D” should be the most processor intensive Condition evaluations, and “Condition_A” should be the least intensive. It is also a good idea to order conditions most likely to be false first - to end Condition evaluation quickly in the case of a negative result.

For more detailed information on Conditions, please see the Condition Types and Actions documentation.

On this page

×

We Dig Feedback

Selected excerpt:

×