1. Handlebars Helpers
  2. If

Handlebars Helpers

If

The "IF" helper is used to conditionally render a block of text based on the truthiness of a data point.

Important
This helper can only be used to evaluate the truthiness of a variable, this means you cannot use any comparison operators like ==, ===, !=, !==, >, <, >=, <=.
You also can't do any arithmetic operations or any other expressions.

WARNING

You will get an error on the _create action when a new stub is created, if you try to use any of the above operations.

NOTE

Example: Basic IF Conditional Rendering

This example shows how to conditionally render a block of text based on the value of a variable.

Example definition:

        {{#if stub.data.is_admin}}
Hello Admin
{{/if}}"


      

If the is_admin variable is true, the output will be:

        Hello Admin

      

If the is_admin variable is false, the output will be empty.

Example: IF-ELSE Conditional Rendering

This example shows how to conditionally render a block of text based on the value of a variable.

Example definition:

        {{#if stub.data.is_admin}}
Hello Admin
{{else}}
Hello User
{{/if}}"


      

If the is_admin variable is true, the output will be:

        Hello Admin

      

If the is_admin variable is false, the output will be:

        Hello User

      

Example ERROR

!This cannot be done!

ERROR

        {{#if stub.data.name == "John"}}
Hello Admin
{{else}}
Hello User
{{/if}}"


      

This will throw an error on the _create action when a new stub is created.