Command Reference CIB jsMerge

JavaScript Control Structures

Conditional Statements

Conditional statements are only executed if the specified condition is met. The syntax for a general if statement is:

if (condition) {
statement
}

To also control what happens when the condition is not met, the if statement can be combined with an else statement:

if (condition) {
statement1
}
else {
statement2
} 
For clarification, the example from chapter Mixed Script and Content Fields is repeated:

{# if(ref(“firstname“)== “Bob“) {Hello Bob!} else {‘Hello everybody!}  } 

If the value of the variable "firstname" is Bob, "Hello Bob" is output, else "Hello everybody" is output.