/
Conditionals

Conditionals

if

You can use the if helper to conditionally render a block. If its argument returns false, undefined, null, "", 0, or [], IdealDoc will not render the block.

{{#if author}} {{firstName}} {{lastName}} {{/if}}

When you pass the following input to the above template

{ author: true, firstName: "Yehuda", lastName: "Katz", }

This will produce the result as below:

Yehuda Katz

If the input is an empty JSONObject {}, then author will become undefined and if condition fails, resulting in an empty output

When using a block expression, you can specify a template section to run if the expression returns a falsy value. The section, marked by else is called an "else section".

with

The with-helper allows you to change the evaluation context of template-part.

when used with this context:

will result in:

with can also be used with block parameters to define known references in the current block. The example above can be converted to:

Which allows for complex templates to potentially provide clearer code than ../ depthed references allow for.

You can optionally provide an {{else}} section which will display only when the passed value is empty.

includeZero

The includeZero=true option may be set to treat the conditional as not empty. This effectively determines if 0 is handled by the positive or negative path.

Conditionals may also be chained by including the subsequent helper call within the else directive.

It is not necessary to use the same helper in subsequent calls, the unless helper could be used in the else portion as with any other helper. When the helper values are different, the closing directive should match the opening helper name.

unless

You can use the unless helper as the inverse of the if helper. Its block will be rendered if the expression returns a falsy value.

If looking up license under the current context returns a falsy value, IdealDoc will render the warning. Otherwise, it will render nothing.

## compare
Syntax
{{compare param1 operator param2}}
param1 and param2 are the parameters to be compared. They can be either static string values enclosed in quotes (e.g. compare “2” “>” “1”) or dynamic variables (e.g. a “>” b).

The operator is a string argument enclosed in quotes defining one of the following operators to be applied:

  • equals: == or ===

  • not equals: != or !==

  • less than: <

  • less or equal: <=

  • greater than: >

  • greater or equal: >=

compare can be used as block or inline expression.

Block Expression:

As single expression:

contains

Block helper that renders the block if collection has the given value, using strict equality (===) for comparison, otherwise the inverse block is rendered (if specified). If a startIndex is specified and is negative, it is used as the offset from the end of the collection.

Example input:

Example template:

concat

Helper which concatenates several strings into one.

Example input:

Example template:

## empty
Inline helper to evaluate whether a given String or an Array or an Object is empty or null/undefined.

Example input:

Example template:

Related content

Variables
Variables
More like this
More about IdealDoc functions
More about IdealDoc functions
More like this
Control Directives
Control Directives
More like this
Lookup
More like this
Iterators
Iterators
More like this
Logical Operators
Logical Operators
More like this