Is this really the version you are looking for? Kentico 9 documentation is no longer updated. Use the switch in the header to choose your Kentico version.

Writing macro conditions

Macro conditions greatly increase the flexibility of certain features. By preparing conditions, you allow the system to dynamically make decisions. For example, when to perform an action, under which circumstances to make an item visible, and so on.

Each condition is defined by a macro expression that returns a true or false value. When the system evaluates the condition, the macro is resolved according to the currently available context data, and the result determines whether the condition is fulfilled or not.

For illustration, the following are examples of functionality that uses macro conditions:

Entering macro conditions

The user interface provides dedicated fields for entering macro conditions. For example, content personalization variants have a Display condition field.

Macro condition field in the form used when editing content personalization variants

You can choose between two ways of creating macro conditions:

In this section

Related pages
Related blogs

Please note: Articles linked here may not reflect the latest version of Kentico. Please report any issues with these links using the feedback form at the bottom of this page.

a) Build the condition out of macro rules

Macro rules are predefined, text-based clauses that define certain requirements. You form the overall condition by combining any number of macro rules. Using macro rules does not require knowledge of K# syntax.

To work with macro rules, click Edit next to the condition field. See Building conditions using macro rules for more information.

b) Write the code of the condition directly

Write a K# macro expression into the condition field. The result must be a boolean value (true/false). Use macro methods with a boolean return type, or comparison and equality operators.

Do not enclose the expression into the standard macro parentheses — the system automatically processes the content of the condition as a K# macro. You can leverage the macro autocomplete help when typing in condition fields.

Tip: If you wish to add a macro condition field into a custom form, use the following form control: Condition builder