# Handlebars Helpers

Email Hero provides a set of custom Handlebars helpers to extend the functionality of your templates. Below is a comprehensive guide to using these helpers.

# 1. each Helper

# Description:

The each helper is used to iterate over an array with options to limit the number of iterations and to skip a certain number of elements.

# Usage:

{{#each array limit=number skip=number}}
  {{!-- Your code here --}}
{{/each}}

# Parameters:

  • array: The array to iterate over.
  • limit: (Optional) The maximum number of items to iterate over.
  • skip: (Optional) The number of items to skip before starting the iteration.

# Example:

{{#each products limit=3 skip=1}}
  <div>
    <h2>{{this.name}}</h2>
    <p>{{this.description}}</p>
    <p>Price: ${{this.price}}</p>
  </div>
{{/each}}

This example will display information for three products, starting with the second item in the products array.

# 2. AND Helper

# Description:

The AND helper returns true if all the provided arguments are truthy.

# Usage:

{{#if (AND condition1 condition2 condition3)}}
  {{!-- Your code here --}}
{{/if}}

# Example:

{{#if (AND user.isActive user.isVerified)}}
  <p>Welcome back, {{user.name}}! Your account is active and verified.</p>
{{else}}
  <p>Please verify your account to access all features.</p>
{{/if}}

This example checks if the user is both active and verified before showing a welcome message.

# 3. OR Helper

# Description:

The OR helper returns true if any of the provided arguments are truthy.

# Usage:

{{#if (OR condition1 condition2 condition3)}}
  {{!-- Your code here --}}
{{/if}}

# Example:

{{#if (OR user.isAdmin user.isModerator)}}
  <p>{{user.name}}, you have administrative privileges.</p>
{{else}}
  <p>{{user.name}}, you do not have administrative privileges.</p>
{{/if}}

This example checks if the user is either an admin or a moderator.

# 4. NOT Helper

# Description:

The NOT helper returns the opposite (boolean negation) of the provided argument.

# Usage:

{{#if (NOT condition)}}
  {{!-- Your code here --}}
{{/if}}

# Example:

{{#if (NOT user.isGuest)}}
  <p>Welcome back, {{user.name}}! You are logged in.</p>
{{else}}
  <p>Welcome! Please log in to continue.</p>
{{/if}}

This example checks if the user is not a guest.

# 5. EQ Helper

# Description:

The EQ (equals) helper checks if two values are strictly equal (===).

# Usage:

{{#if (EQ value1 value2)}}
  {{!-- Your code here --}}
{{/if}}

# Example:

{{#if (EQ user.subscriptionType 'premium')}}
  <p>Thank you for being a premium subscriber, {{user.name}}!</p>
{{else}}
  <p>Consider upgrading to premium to enjoy additional benefits.</p>
{{/if}}

This example checks if the user has a premium subscription.

# 6. INCLUDES Helper

# Description:

The INCLUDES helper checks if an array contains a specific value.

# Usage:

{{#if (INCLUDES array value)}}
  {{!-- Your code here --}}
{{/if}}

# Example:

{{#if (INCLUDES user.roles 'admin')}}
  <p>{{user.name}}, you have admin access.</p>
{{else}}
  <p>{{user.name}}, you do not have admin access.</p>
{{/if}}

This example checks if the user's roles array includes 'admin'.

# 7. CAPITALIZE Helper

# Description:

The CAPITALIZE helper converts a string to uppercase.

# Usage:

{{CAPITALIZE string}}

# Example:

<p>{{CAPITALIZE user.name}}</p>

If user.name is "john doe", this will output: <p>JOHN DOE</p>.

# 8. TRUNCATE Helper

# Description:

The TRUNCATE helper truncates a string to a specified number of characters, appending "..." if the string is longer than the specified length.

# Usage:

{{TRUNCATE text characterNum}}

# Parameters:

  • text: The text to truncate.
  • characterNum: The maximum number of characters before truncation.

# Example:

<p>{{TRUNCATE 'This is an example of a very long sentence that needs to be shortened.' 30}}</p>

This will output: <p>This is an example of a very...</p>


These helpers allow you to perform various logical, string, and array operations directly within your Handlebars templates, giving you more power and flexibility in your email templates.