Conditional logic

You can control logic within your template using a number of conditional statements including:

  • {{#if } {{/else}} {{/if }} - this checks for the existence of something (this does not check equality)

  • {{#unless}} {{/else}} {{/unless}} - this checks for the non-existence of something (this does not check non-equality)

  • {{#equal}} {{/else}} {{/equal}} - this checks equality, i.e. if something equals something

Example 1:

{{#if (Request.QueryParam.price) }}
	A price of {{ Request.QueryParam.price }} was provided

	{{#equal Request.QueryParam.price "10"}}
    		Price is 10!
	{{else}}
		Price is something other than 10.
  	{{/equal}}
{{else}}
	No price was provided
{{/if}}

Example 2:

{{#unless Request.QueryParam.product}}
	No product was provided
{{else}}
	A product named "{{Request.QueryParam.product}}" was provided
{{/unless}}

Follow a tutorial here to learn more about conditionals and equality

Last updated