Conditions

Selectively Showing and Hiding Content

With conditions (conditionals), you can show or hide text sections in preview and output. This is especially useful in combination with Products to customize content for different target audiences.

There are three types of conditions:

Syntax Effect

ifdef::attribute[]

Content is shown if the attribute is defined

ifndef::attribute[]

Content is shown if the attribute is not defined

ifeval::[expression]

Content is shown if the expression is true

ifdef and ifndef

The simplest condition checks whether an attribute exists:

 ifdef::ipad[]
 This text appears only in the iPad version.
 endif::[]

 ifndef::ipad[]
 This text appears in all versions except iPad.
 endif::[]

For short texts, there’s a single-line variant without endif:

 ifdef::print[Only visible in print.]
 ifndef::print[Only visible online.]

You can also combine multiple attributes:

 ifdef::mac,ipad[]
 Appears if mac OR ipad is defined.
 endif::[]

 ifdef::mac+pro[]
 Appears only if mac AND pro are defined.
 endif::[]

ifeval for Complex Conditions

With ifeval, you can evaluate expressions:

 ifeval::[{version} >= 2]
 This feature is available from version 2.0.
 endif::[]

 ifeval::["{lang}" == "en"]
 English content
 endif::[]

Available operators: ==, !=, <, <=, >, >=

Conditions are supported by the adoc Coach. Press ESC after if for suggestions.
Conditions reach their full potential in combination with products. Define attributes like :ipad: or :beginner: in your products and use them to control which content appears in which output.