Client Side Template

{*ensure var 1,var 2,var 3}

Description

Protects the existence of data variables.

The ensure directive allows you to ensure certain properties exist in the Data.

{*ensure a,b,c}

Where a, b and c are data variables that you want to define so that if they are referenced in an {*if} block, the {*if} block will evaluate correctly. For example, assume the data passsed to a template is:

{bar: 'world'}

And the template is defined as:

{*if foo == 'hello'}
...
{*elseif bar == 'world'}
...
{*else}
...
{*endif}

Without {*ensure foo}, the {*if} block will not execute correctly, as foo doesn't exist.

Error merging data into template

Here is how the template could be rewritten to ensure that it works as expected:

{*ensure foo}
{*if foo == 'hello'}
...
{*elseif bar == 'world'}
...
{*else}
...
{*endif}