Template administrators Microsoft Word How do you use an IF and ELSE

How do you use an IF and ELSE

Published on: July 1, 2024
Edited on: November 28, 2024

When creating Documents or Smart Documents, you have likely encountered 'if' and 'else'. This option allows you to display or hide certain elements based on the value of a variable. In this article, we will explain everything you need to know about 'if-else'.

IF

Within a document, you can use 'if' to conditionally display or hide elements. You do this by setting a condition: if this condition is met, a certain action is performed. If the condition is not met, the 'else' is evaluated.

Inserting an IF

To insert an 'if', you first need to edit a template. Then you can select a piece of text (or something else) in the document. After making a selection, click on the 'Play' icon.

A menu with various options will now open. Click on the 'Insert If' option to insert an 'if'. In the image below, this option is circled.

A new element will then open in the sidebar. In this new element, you can enter an 'Expression'. Below is an example of how this new element looks.

An expression is composed of different parts. In the article 'Using expressions', you will find an overview of all the expressions you can use.

Example of an IF

If you have added an 'if', it will appear as follows:

[IF = expression][ENDIF]

When you use the 'if' it should look like this:

[IF = Variables.IsEqual("Name", "Engine")]
Show this if the value of the "Name" variable is "Engine"
[ENDIF]

ELSE

You can also insert an 'else' in a document. An 'else' is used in combination with an 'if'. It allows you to perform an alternative action when the 'if' condition is not met.

Inserting an ELSE

Adding an 'else' is slightly different from inserting an 'if'. You still need to edit a template, but an 'else' can only be inserted within an 'if' (before an [ENDIF]). When you are at the location where the 'else' should go, click on the 'Play' icon.

After clicking the icon in the image above, a menu with various options opens. Choose the 'Insert else' option from the menu. This option directly adds an 'else' to the document.

Warning icon

Warning!

Make sure to insert the 'else' within the 'if' (before the [ENDIF] element).

Example of an ELSE

If you have added an 'else', it will appear as follows:

[ELSE]

When using the 'else', it should look like this:

[IF = Variables.IsEqual("Name", "Engine")]
Show this if the value of the "Name" variable is "Engine"
[ELSE]
Show this if the value of the "Name" variable is something other than "Engine"
[ENDIF]