Skip to content

Latest commit

 

History

History
38 lines (28 loc) · 839 Bytes

null-coalescing-operator.md

File metadata and controls

38 lines (28 loc) · 839 Bytes

?? Operator

The null coalescing operator ?? can be used to return default values.

If the expression left of the ?? operator evaluates to null, the expression to the right of the operator is evaluated.

The operator can be used in all templating commands that allow expressions, such as placeholder, if, elseif or loops.

Input:

{}

Template:

{
    "name": {{ user/name ?? "unkown" }}
}

Output:

{
  "name": "unknown"
}

The ?? operator can be used multiple times in a template expression:

{
  "name": {{ user/name ?? user/mail ?? "unknown" }}
}

📎 Note that ?? operator(s) are used to split the template expression into subexpressions and therefore cannot be used in arguments of functions within those subexpressions.