Conditional syntax such as {{#if VARIABLE_NAME }} Content {{/if}} can be used to dynamically show or hide specific content depending on if a variable is set or not.

The use cases of this powerful feature are far many to count, but here are a few common use cases to get you started:

Show a particular line of text only when a variable is set:

Let's say you have the following line of text:

Client Name: {{Client.Name}}

As it is now if the client's name is not actually set then it will show like this:

Client Name:

Which looks broken and not very professional. Instead what you would want to do is to completely hide the text "Client Name:" if the client name is not actually set.

To do that you would use the {{#if}} syntax.

First, wrap the text "Client Name:" in the syntax as follows:

{{#if}} Client Name: {{/if}}

Then add the variable name to the first/opening {{#if}} as follows:

{{#if Client.Name }} Client Name: {{/if}}

That's it. Now the text "Client Name:" will only show if there is value set to the connected variable.

๐Ÿ’ก Good to know: this also works for any type of content such as images, videos, lists etc.. Simply wrap the desired content with the {{#if}} {{/if}} syntax.

Hide a particular line of text when a variable is set:

Using the same exact technique described in the first point, but instead of {{#if}} we would use {{#unless}} which then hides the content wrapped inside it when a variable is set.

Simply put, using {{#unless}} achieves the opposite results of {{#if}}

Advanced conditional variables:

Applying the same logic explained above you can use another conditional syntax to achieve more advanced results.

1) Don't show content if the variable is set:

Using {{#unless}} instead of {{#if}} would HIDE the content if the variable is set.

2) Show certain content if the variable is set and different content if the variable isn't set by using {{else}}.

{{#if}} Show This If Set {{else}} Show This If Not Set {{/if}}


{{#unless}} Show This If Not Set {{else}} Don't Show This If Set {{/unless}}

Did this answer your question?