Handlebars - Comparison Helpers

Mat Bradley-Tschirgi

Table of Contents

Comparison Helpers allow you to compare values in Handlebars in a few different ways. The comparison helpers allow the handlebars to display different text depending if certain conditions are met by comparing fields to each other.

Here are examples of Comparison Helpers:

  • eq - Checks if two values are equal 
    • Syntax: {{#if (and value1 value2 value3 ...)}}
      • Example: {{#if (eq [Country] "United States")}}
        <p>Free shipping on all orders!</p>
        {{else}}
        <p>International shipping rates apply.</p>
        {{/if}}
  • ne - Checks if two values are not equal
    • Syntax: {{#if (ne value1 value2)}}
      • Example: {{#if (ne [Membership-Level] "VIP")}}
        <p>Upgrade to VIP to unlock premium content!</p>
        {{/if}}
  • gt - Checks if a numeric value is greater than another; only works with numeric values. 
    • Syntax: {{#if (gt value1 value2)}}
      • Example: {{#if (gt [Age] 21)}}
        <p>Check out our wine collection!</p>
        {{/if}}
  • lt - Checks if a numeric value is less than another
    • Syntax: {{#if (lt value1 value2)}}
      • Example: {{#if (lt [Days-Until-Expiration] 7)}}
        <p><strong>URGENT:</strong> Your membership expires in {{[Days-Until-Expiration]}} days!</p>
        {{/if}}
The Pinpointe Playbook