> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://fyno.io/docs/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://fyno.io/docs/_mcp/server.

# Handlebars

> Learn how to use Handlebars in Fyno templates, or generate them with Fyno AI, to create dynamic content with placeholders, conditional logic, loops, date formatting, mathematical operations, custom helpers, and advanced template expressions.

Handlebars is a JavaScript library used for creating dynamic templates.

It allows you to define templates with placeholders, and these placeholders are replaced with data when the template is triggered with the information sent in the payload.

Handlebars within Fyno support features like conditional operations, loops, date time formatting, partial searches, and custom helpers, making it a powerful tool for building your templates.

## Handlebars in Fyno's Templates

To understand how handlebars work, we first need to establish a sample payload, based off which the Handlebars function and applicability can be demonstrated.

**`Sample Payload`**

```json Sample Payload
{
  "members": [
    {
      "first_name": "Ashwin",
      "last_name": "Agarwal",
      "city": ""
    }
  ],
  "investments": [
    {
      "amount": 10,
      "company": "L&T"
    },
    {
      "amount": 20
    }
  ],
  "companies": {
    "L&T": "India",
    "Apple": "USA"
  },
  "user_type": "pro",
  "period": {
    "start": "2023-10-01",
    "end": "2023-10-03"
  },
  "classification": ["active", "pro"]
}
```

Fyno has default as well as custom **handlebars** that you can use in your templates. Let's have a look at what these are and how to use them using the above payload and data as example responses. You can also [generate handlebars with Fyno AI](#generate-handlebars-with-fyno-ai) by describing what you need in plain language.

> **Use single quotes inside handlebars**
>
> Double quotes inside handlebars can break your template syntax, especially in emails. Use single quotes instead. For example, use `{{math number1 '+' number2}}` instead of `{{math number1 "+" number2}}`.

#### To access placeholder values

**`Format`**

```hbs title="Format" wordWrap
{{key}}
```

**`Example`**

```hbs title="Example" wordWrap
{{user_type}}
```

**`Output`**

```text title="Output" wordWrap
pro
```

#### To access values of an object

**`Format`**

```hbs title="Format" wordWrap
{{key.subkey}}
```

**`Example`**

```hbs title="Example" wordWrap
{{period.start}} to {{period.end}}
```

**`Output`**

```text title="Output" wordWrap
2023-10-01 to 2023-10-03
```

#### To access object values from an array

**`Format`**

```hbs title="Format" wordWrap
{{key.index.subkey}}
```

**`Example`**

```hbs title="Example" wordWrap
{{members.0.first_name}}
```

**`Output`**

```text title="Output" wordWrap
Ashwin
```

#### To access values from an array

**`Format`**

```hbs title="Format" wordWrap
{{key.index}}
```

**`Example`**

```hbs title="Example" wordWrap
{{classification.0}}
```

**`Output`**

```text title="Output" wordWrap
active
```

#### To avoid escaping the values

**`Format`**

```hbs title="Format" wordWrap
{{{key}}}
```

**`Example`**

```hbs title="Example" wordWrap
{{{investments.0.company}}}
```

> **Note**
>
> If you use double braces instead of triple, L\&T shows as `L&amp;T`.

**`Output`**

```text title="Output" wordWrap
L&T
```

#### To get length of an array

**`Format`**

```hbs title="Format" wordWrap
{{key.length}}
```

**`Example`**

```hbs title="Example" wordWrap
User made {{investments.length}} investments
```

**`Output`**

```text title="Output" wordWrap
User made 2 investments
```

#### To check if variable exists

**`Format`**

```hbs title="Format" wordWrap
{{#if variable}}
  Content Here
{{else if variable}}
  Content Here
{{else}}
  Content Here
{{/if}}
```

**`Example`**

```hbs title="Example" wordWrap
{{#if members.0.city}}
  City available for member 1 and may be member 2
{{else if members.1.city}}
  City available for member 2 only
{{else}}
  City not available for member 1 and 2
{{/if}}
```

**`Output`**

```text title="Output" wordWrap
City available for member 1 and may be member 2
```

#### Approach 1: To check if variable equals a certain value

**`Format`**

```hbs title="Format" wordWrap
{{#if (eq variable 'value')}}
  Content Here
{{else if (eq variable 'value')}}
  Content Here
{{/if}}
```

**`Example`**

```hbs title="Example" wordWrap
{{#if (eq investments.0.company 'L&T')}}
  First investment was L&T
{{else if (eq investments.0.company 'Apple')}}
  First investment was Apple
{{else}}
  First investment was neither Apple nor L&T
{{/if}}
```

**`Output`**

```text title="Output" wordWrap
First investment was L&T
```

#### Approach 2: To check if variable equals a certain value

**`Format`**

```hbs title="Format" wordWrap
{{#ifEquals variable 'value'}}
  Content Here
{{else ifEquals variable 'value'}}
  Content Here
{{else}}
  Content Here
{{/ifEquals}}
```

**`Example`**

```hbs title="Example" wordWrap
{{#ifEquals investments.0.company 'L&T'}}
  First investment was L&T
{{else ifEquals investments.0.company 'Apple'}}
  First investment was Apple
{{else}}
  First investment was neither Apple nor L&T
{{/ifEquals}}
```

**`Output`**

```text title="Output" wordWrap
First investment was L&T
```

#### To check if multiple variables equal a certain value (AND and OR options)

**`Format`**

```hbs title="Format" wordWrap
{{#if (and/or (eq/ne/lt/gt/lte/gte variable 'value') (eq/ne/lt/gt/lte/gte variable 'value'))}}
  Content Here
{{else}}
  Content Here
{{/if}}
```

**`Example`**

```hbs title="Example" wordWrap
{{#if (or (eq investments.0.company 'L&T') (eq investments.0.company 'Apple'))}}
  First investment is either L&T OR Apple
{{/if}}

{{#if (and (eq investments.0.company 'L&T') (gt investments.0.amount 5))}}
  First investment is L&T and investment amount is greater than 5
{{/if}}

{{#if (and (ne user_type 'pro') (gte investments.0.amount 10))}}
  User is not pro but first investment is greater than or equal to 10
{{else if (and (eq user_type 'pro') (lt investments.0.amount 10))}}
  User type is pro but first investment is less than 10
{{else if (and (eq user_type 'pro') (eq investments.0.amount 10))}}
  User type is pro and first investment is equal to 10
{{/if}}
```

**`Output`**

```text title="Output" wordWrap
First investment is either L&T OR Apple

First investment is L&T and investment amount is greater than 5

User type is pro and first investment is equal to 10
```

#### To check if variable equals a regular expression

**`Format`**

```hbs title="Format" wordWrap
{{#ifMatches variable 'regex'}}
  Content Here
{{else ifMatches variable 'regex'}}
  Content Here
{{else}}
  Content Here
{{/ifMatches}}
```

**`Example`**

```hbs title="Example" wordWrap
{{#ifMatches members.0.last_name 'Aga\*'}}
  Matched
{{else}}
  Not matched
{{/ifMatches}}
```

**`Output`**

```text title="Output" wordWrap
Matched
```

#### To check if string starts with certain characters

**`Format`**

```hbs title="Format" wordWrap
{{#ifStartsWith variable 'value'}}
  Content Here
{{else ifStartsWith variable 'value'}}
  Content Here
{{else}}
  Content Here
{{/ifStartsWith}}
```

**`Example`**

```hbs title="Example" wordWrap
{{#ifStartsWith members.0.first_name 'A'}}
  Name starts with A
{{else}}
  Name does not start with A
{{/ifStartsWith}}
```

**`Output`**

```text title="Output" wordWrap
Name starts with A
```

#### To use OR operator between two variables

**`Format`**

```hbs title="Format" wordWrap
{{#compare var1 'or' var2}}
  Content Here
{{else compare var1 'or' var2}}
  Content Here
{{/compare}}
```

**`Example`**

```hbs title="Example" wordWrap
{{#compare investments.0.amount 'or' investments.1.amount}}
  Invested at least once
{{else}}
  No investment made
{{/compare}}
```

**`Output`**

```text title="Output" wordWrap
Invested at least once
```

#### To use AND operator between two variables

**`Format`**

```hbs title="Format" wordWrap
{{#compare var1 'and' var2}}
  Content Here
{{else compare var1 'and' var2}}
  Content Here
{{/compare}}
```

**`Example`**

```hbs title="Example" wordWrap
{{#compare investments.0.amount 'and' investments.1.amount}}
  Invested at least twice
{{else}}
  One or fewer investments made
{{/compare}}
```

**`Output`**

```text title="Output" wordWrap
Invested at least twice
```

#### To use a specified default value if the actual value does not exist (or is null)

**`Format`**

```hbs title="Format" wordWrap
{{default variable 'value'}}
```

**`Example`**

```hbs title="Example" wordWrap
{{default members.0.city 'Bangalore'}}
```

**`Output`**

```text title="Output" wordWrap
Bangalore
```

#### To sum two numbers

**`Format`**

```hbs title="Format" wordWrap
{{math number1 '+' number2}}
```

**`Example`**

```hbs title="Example" wordWrap
{{math investments.0.amount '+' investments.1.amount}}
```

**`Output`**

```text title="Output" wordWrap
30
```

#### To subtract two numbers

**`Format`**

```hbs title="Format" wordWrap
{{math number1 '-' number2}}
```

**`Example`**

```hbs title="Example" wordWrap
{{math investments.1.amount '-' investments.0.amount}}
```

**`Output`**

```text title="Output" wordWrap
10
```

#### To multiply two numbers

**`Format`**

```hbs title="Format" wordWrap
{{math number1 '*' number2}}
```

**`Example`**

```hbs title="Example" wordWrap
{{math investments.0.amount '*' investments.1.amount}}
```

**`Output`**

```text title="Output" wordWrap
200
```

#### To divide numbers

**`Format`**

```hbs title="Format" wordWrap
{{math number1 '/' number2}}
```

**`Example`**

```hbs title="Example" wordWrap
{{math investments.0.amount '/' investments.1.amount}}
```

**`Output`**

```text title="Output" wordWrap
0.5
```

#### To perform modulo

**`Format`**

```hbs title="Format" wordWrap
{{math number1 '%' number2}}
```

**`Example`**

```hbs title="Example" wordWrap
{{math investments.0.amount '%' investments.1.amount}}
```

**`Output`**

```text title="Output" wordWrap
10
```

#### To round numbers

**`Format`**

```hbs title="Format" wordWrap
{{math number 'round' decimal_places}}
```

**`Example`**

```hbs title="Example" wordWrap
{{math investments.0.amount 'round' 2}}
{{math investments.0.amount 'round'}}
```

**`Output`**

```text title="Output" wordWrap
10.00
10
```

#### To check for negative condition (show something only if key doesn't exist)

**`Format`**

```hbs title="Format" wordWrap
{{#unless key}}
  Content Here
{{/unless}}
```

**`Example`**

```hbs title="Example" wordWrap
{{#unless investments}}
  Investments were not made!
{{else}}
  Investments were made!
{{/unless}}
```

**`Output`**

```text title="Output" wordWrap
Investments were made!
```

#### To iterate over a list/array

**`Format`**

```hbs title="Format" wordWrap
{{#each key}}
  {{this.subkey}}
{{/each}}
```

**`Example`**

```hbs title="Example" wordWrap
{{#each investments}}
  {{math @index '+' 1}}.
  {{{default this.company 'Not known'}}}
  - ${{this.amount}}
{{else}}
  No investments were made!
{{/each}}
```

**`Output`**

```text title="Output" wordWrap
1. L&T - $10

2. Not known - $20
```

#### To use combination of conditions and nesting (advanced)

**`Format`**

```hbs title="Format" wordWrap
{{#if variable}}
  Content Here
{{else}}
  {{#ifEquals variable 'value'}}
    Content Here
  {{else}}
    {{#ifMatches variable 'regex'}}
      Content Here
    {{else}}
      {{#ifStartsWith variable 'value'}}
        Content Here
      {{else}}
        {{#if (eq var1 var2)}}
          Content Here
        {{/if}}
      {{/ifStartsWith}}
    {{/ifMatches}}
  {{/ifEquals}}
{{/if}}
```

**`Example`**

```hbs title="Example" wordWrap
{{#if investments}}
  {{#ifEquals investments.0.company 'Apple'}}
    Invested in Apple Inc!
  {{else}}{{#ifMatches investments.0.company 'Amazon\*'}}
      Invested in Amazon ventures!
    {{else}}{{#ifStartsWith investments.0.company 'Microsoft'}}
        Invested in Microsoft!
      {{else}}{{#if (eq investments.0.company 'L&T')}}
          Invested in Larsen & Toubro!
        {{/if}}
      {{/ifStartsWith}}
    {{/ifMatches}}
  {{/ifEquals}}
{{else}}
  No investments were made!
{{/if}}
```

**`Output`**

```text title="Output" wordWrap
Invested in Larsen & Toubro!
```

#### To lookup values and use them in placeholders (advanced)

**`Format`**

```hbs title="Format" wordWrap
{{#each iterate_key}}
    {{subkey}}
    {{lookup ../key [subkey]}}
{{/each}}
```

**`Example`**

```hbs title="Example" wordWrap
{{#each investments as | investment |}}
    {{#if company}}
        {{{company}}} is in {{lookup ../companies [company]}}
    {{/if}}
{{/each}}
```

**`Output`**

```text title="Output" wordWrap
L&T is in India
```

#### To split variables and get value at index

**`Format`**

```hbs title="Format" wordWrap
{{split variable_name 'delimiter' index}}
```

**`Example`**

```hbs title="Example" wordWrap
{{split period.start '-' -1}}/{{split period.start '-' 1}}/{{split period.start '-' 0}} {{split period.end '-' -1}}/{{split period.end '-' 1}}/{{split period.end '-' 0}}
```

**`Output`**

```text title="Output" wordWrap
01/10/2023

03/10/2023
```

#### To split variables and loop on it

**`Format`**

```hbs title="Format" wordWrap
{{#each (split variable_name 'delimiter')}}
  {{this}}
{{/each}}
```

**`Example`**

```hbs title="Example" wordWrap
{{#each (split period.start '-')}}
  {{this}}
{{/each}}
```

**`Output`**

```text title="Output" wordWrap
2023

10

01
```

#### To check if timestamp equals to today or yesterday or tomorrow

**`Format`**

```hbs title="Format" wordWrap
{{relativeDay timestamp_with_timezone}}
```

**`Example`**

```hbs title="Example" wordWrap
{{relativeDay '2023-10-25T14:30:00+05:30'}}
{{relativeDay '2023-10-26T14:30:00+05:30'}}
{{relativeDay '2023-10-24T14:30:00+05:30'}}
{{relativeDay period.start}}
{{#ifEquals (relativeDay '2023-12-19T14:30:00+05:30') 'today'}}
  The date is today!
{{else}}
  The date is not today!
{{/ifEquals}}
```

**`Output`**

```text title="Output" wordWrap
today
tomorrow
yesterday
before
The date is today!
```

#### To check the difference between two dates (in ms, seconds, minutes, hours, days, weeks, months or years)

**`Format`**

```hbs title="Format" wordWrap
{{dateDiff timestamp1_with_timezone timestamp2_with_timezone 'ms / seconds / minutes / hours / days / weeks / months / years'}}
```

> **Note**
>
> The date and time must be in RFC 3339 or ISO 8601 format, or the helper returns NaN.

**`Example`**

```hbs title="Example" wordWrap
{{dateDiff '2023-12-01T14:30:00+05:30' '2023-12-19T14:30:00+05:30' 'ms'}}
ms
{{dateDiff '2023-12-01T14:30:00+05:30' '2023-12-19T14:30:00+05:30' 'seconds'}}
secs
{{dateDiff '2023-12-01T14:30:00+05:30' '2023-12-19T14:30:00+05:30' 'minutes'}}
mins
{{dateDiff '2023-12-01T14:30:00+05:30' '2023-12-19T14:30:00+05:30' 'hours'}}
hours
{{dateDiff '2023-12-01T14:30:00+05:30' '2023-12-19T14:30:00+05:30' 'days'}}
days
{{dateDiff '2023-12-01T14:30:00+05:30' '2023-12-19T14:30:00+05:30' 'weeks'}}
weeks
{{dateDiff '2023-12-01T14:30:00+05:30' '2023-12-19T14:30:00+05:30' 'months'}}
months
{{dateDiff '2023-12-01T14:30:00+05:30' '2023-12-19T14:30:00+05:30' 'year'}}
years Since
{{dateDiff '2023-12-01T14:30:00+05:30' 'NOW' 'days'}}
days

{{#if (gt (dateDiff '2023-12-01T14:30:00+05:30' 'NOW' 'days') 10)}}
  More than 10 days!
{{else}}
  Less than 10 days!
{{/if}}
```

**`Output`**

```text title="Output" wordWrap
1555200000 ms
1555200 secs
25920 mins
432 hours
18 days
2 weeks
0 months
0 years

Since 18 days

More than 10 days!
```

#### To format date value

**`Format`**

```hbs title="Format" wordWrap
{{formatDate timestamp_with_timezone 'short'}}
{{formatDate timestamp_with_timezone 'short' 'en-in'}}
{{formatDate timestamp_with_timezone 'short' 'en-in' '+05:30'}}
{{formatDate timestamp_with_timezone 'medium'}}
{{formatDate timestamp_with_timezone 'medium' 'en-in'}}
{{formatDate timestamp_with_timezone 'medium' 'en-in' '+05:30'}}
{{formatDate timestamp_with_timezone 'long'}}
{{formatDate timestamp_with_timezone 'long' 'en-in'}}
{{formatDate timestamp_with_timezone 'long' 'en-in' '+05:30'}}
```

**`Example`**

```hbs title="Example" wordWrap
{{formatDate '2023-10-25T18:30:00Z' 'short'}}
{{formatDate '2023-10-25T18:30:00Z' 'short' 'en-in'}}
{{formatDate '2023-10-25T18:30:00Z' 'short' 'en-in' '+05:30'}}
{{formatDate '2023-10-25T18:30:00Z' 'medium'}}
{{formatDate '2023-10-25T18:30:00Z' 'medium' 'en-in'}}
{{formatDate '2023-10-25T18:30:00Z' 'medium' 'en-in' '+05:30'}}
{{formatDate '2023-10-25T18:30:00Z' 'long'}}
{{formatDate '2023-10-25T18:30:00Z' 'long' 'en-in'}}
{{formatDate '2023-10-25T18:30:00Z' 'long' 'en-in' '+05:30'}}
```

**`Output`**

```text title="Output" wordWrap
10/25/2023
25/10/2023
26/10/2023
Oct 25, 2023
25 Oct 2023
26 Oct 2023
October 25, 2023
25 October 2023
26 October 2023
```

#### To format datetime value

**`Format`**

```hbs title="Format" wordWrap
{{formatDateTime timestamp_with_timezone 'short'}}
{{formatDateTime timestamp_with_timezone 'short' 'en-in'}}
{{formatDateTime timestamp_with_timezone 'short' 'en-in' '+05:30'}}
{{formatDateTime timestamp_with_timezone 'medium'}}
{{formatDateTime timestamp_with_timezone 'medium' 'en-in'}}
{{formatDateTime timestamp_with_timezone 'medium' 'en-in' '+05:30'}}
{{formatDateTime timestamp_with_timezone 'long'}}
{{formatDateTime timestamp_with_timezone 'long' 'en-in'}}
{{formatDateTime timestamp_with_timezone 'long' 'en-in' '+05:30'}}
{{formatDateTime timestamp_with_timezone 'custom' 'en-in' '+05:30'}}
```

**`Example`**

```hbs title="Example" wordWrap
{{formatDateTime '2023-10-25T18:30:00Z' 'short'}}
{{formatDateTime '2023-10-25T18:30:00Z' 'short' 'en-in'}}
{{formatDateTime '2023-10-25T18:30:00Z' 'short' 'en-in' '+05:30'}}
{{formatDateTime '2023-10-25T18:30:00Z' 'medium'}}
{{formatDateTime '2023-10-25T18:30:00Z' 'medium' 'en-in'}}
{{formatDateTime '2023-10-25T18:30:00Z' 'medium' 'en-in' '+05:30'}}
{{formatDateTime '2023-10-25T18:30:00Z' 'long'}}
{{formatDateTime '2023-10-25T18:30:00Z' 'long' 'en-in'}}
{{formatDateTime '2023-10-25T18:30:00Z' 'long' 'en-in' '+05:30'}}
{{formatDateTime '2023-10-25T18:30:00Z' 'custom' 'en-in' '+05:30'}}
```

**`Output`**

```text title="Output" wordWrap
25/10/2023, 18:30
25/10/2023, 06:30 pm
26/10/2023, 12:00 am
25 Oct 2023, 18:30
25 Oct 2023, 06:30 pm
26 Oct 2023, 12:00 am
25 October 2023 at 18:30
25 October 2023 at 06:30 pm
26 October 2023 at 12:00 am
26 October 2023 at 12:00:00 am
```

#### To format numeric value

**`Format`**

```hbs title="Format" wordWrap
{{formatNumber number}}
{{formatNumber number 'en-in'}}
{{formatNumber (math number 'round') 'en-in'}}
```

**`Example`**

```hbs title="Example" wordWrap
{{formatNumber 4000000.112}}
{{formatNumber 4000000.112 'en-in'}}
{{formatNumber (math 4000000.11 'round') 'en-in'}}
{{formatNumber 4000000.112 'en-in' 'notation=compact'}}
{{formatNumber 4000000.112 'en-US' 'notation=compact'}}
{{formatNumber 42456235.112 'en-US' 'notation=compact, minimumFractionDigits=2, maximumFractionDigits=2, style=currency, currency=USD'}}
{{formatNumber 42456235.112 'en-in' 'notation=compact, minimumFractionDigits=2, maximumFractionDigits=2, style=currency, currency=INR'}}
```

**`Output`**

```text title="Output" wordWrap
4,000,000.112
40,00,000.112
40,00,000
40L
4M
$42.46M
₹4.25Cr
```

#### To trim spaces from value

**`Format`**

```hbs title="Format" wordWrap
{{trim variable_name}}
```

**`Example`**

```hbs title="Example" wordWrap
{{trim ' Test Name '}}
```

**`Output`**

```text title="Output" wordWrap
Test Name
```

#### To trim values to a particular length

**`Format`**

```hbs title="Format" wordWrap
{{trim variable_name max_length}}
```

**`Example`**

```hbs title="Example" wordWrap
{{trim 'First Middle Last Name' 20}}
```

**`Output`**

```text title="Output" wordWrap
First Middle Last Na
```

#### To trim value to a particular length and then truncate until the last occurrence of the specified delimiter

**`Format`**

```hbs title="Format" wordWrap
{{trim variable_name max_length delimiter}}
```

**`Example`**

```hbs title="Example" wordWrap
{{trim 'First Middle Last Name' 20 ' '}}
```

**`Output`**

```text title="Output" wordWrap
First Middle Last
```

#### To remove a string

**`Format`**

```hbs title="Format" wordWrap
{{remove variable_name 'remove_char/string'}}
```

**`Example`**

```hbs title="Example" wordWrap
{{remove 'Fyno™' '™'}}
{{remove 'Fyno®' '®'}}
{{remove 'Fyno®™' '®|™'}}
```

**`Output`**

```text title="Output" wordWrap
Fyno
Fyno
Fyno
```

#### To sum multiple numbers

**`Format`**

```hbs title="Format" wordWrap
{{sumAll start_key 'number_key'}}
```

**`Example`**

```hbs title="Example" wordWrap
{{sumAll @root 'investments.amount'}}
{{formatNumber (sumAll @root 'investments.amount') 'en-US' 'style=currency, currency=USD'}}
```

**`Output`**

```text title="Output" wordWrap
30
$30.00
```

#### Current time with date format

**`Format`**

```hbs title="Format" wordWrap
{{moment start_time format='date_format'}}
```

**`Example`**

```hbs title="Example" wordWrap
{{moment start_time format='D/M/Y'}}
{{moment start_time format='D/M/Y hh:mm A'}}
{{moment start_time format='dddd, D MMMM'}}
{{moment start_time format='dddd, Do MMMM Y HH:mm Z'}}
{{moment start_time format='DD/MM/YYYY'}}
```

**`Output`**

```text title="Output" wordWrap
26/11/2024
26/11/2024 02:51 PM
Tuesday, 26 November
Tuesday, 26th November 2024 14:54 +05:30
26/11/2024
```

#### Specific time with formatting and timezone

**`Format`**

```hbs title="Format" wordWrap
{{moment date format='date_format' tz='timezone'}}
```

**`Example`**

```hbs title="Example" wordWrap
{{moment '1722605334190' format='D/M/Y'}}
{{moment '1722605334190' format='DD/MM/YYYY hh:mm A'}}
{{moment '1722605334190' format='dddd, D MMMM'}}
{{moment '1722605334190' format='dddd, Do MMMM Y HH:mm Z'}}
{{moment '1722605334190' format='dddd, Do MMMM Y HH:mm Z' tz='Europe/Andorra'}}
```

**`Output`**

```text title="Output" wordWrap
2/8/2024
02/08/2024 06:58 PM
Friday, 2 August
Friday, 2nd August 2024 18:58 +05:30
Friday, 2nd August 2024 15:28 +02:00
```

#### Convert Number to Words

**`Format`**

```hbs title="Format" wordWrap
{{numberToWord number}}
```

**`Example`**

```hbs title="Example" wordWrap
{{numberToWord 6}}
{{numberToWord 6231}}
{{numberToWord 100000000}}
```

**`Output`**

```text title="Output" wordWrap
six
six thousand two hundred thirty one
one hundred million
```

#### Convert Unicode to Non Unicode characters

**`Format`**

```hbs title="Format" wordWrap
{{unidecode variable_name}}
```

**`Example`**

```hbs title="Example" wordWrap
{{unidecode Hello® |®|™}}
{{unidecode Ryyúuy}}
{{unidecode नमस्ते, आप कैसे हैं?}}
```

**`Output`**

```text title="Output" wordWrap
Hello(r) |(r)|tm
Ryyuuy
nmste, aap kaise haiN?
```

## Generate Handlebars with Fyno AI

Don't want to write the syntax yourself? Describe what you need in plain language, and Fyno AI will generate a ready-to-use handlebar for you.

### Where to find it

You can open the generator from two places:

* **Left panel on the template page:** Expand **Handlebars** > **Build Your Own** and click **Generate**. If you'd rather build the logic yourself, this section also links to the [Handlebars Builder](#handlebars-builder).
* **AI menu on input fields:** Any field that supports handlebars has an AI menu. Choose **Generate Handlebar** from it.

The AI menu also has **Improve Handlebars**, which refines a handlebar that's already in the field instead of starting from scratch.

![Build Your Own section in the left panel, with the Generate button](/docs/_fern-img/da998769e8d08ab0686a4f83270762bec20993d8d601cb058244922d3d754af0.webp)

### Generate a handlebar

#### Describe your requirement

In the **Generate Handlebars** window, describe what the handlebar should do. For example: *Show order_date in short Indian date format.* Then click **Generate**.

> **Note**
>
> Fyno AI works only with placeholders that already exist in your template. For example, to show a date in a specific format, the date must already be a placeholder in your template.

![Generate Handlebars window with a requirement entered](/docs/_fern-img/ecb55525e7858f3c5777a83e22e000254191d5cc1a3c16e4b6aed8470f96b01b.webp)

#### Let Fyno AI work

While **Brewing your handlebar** is shown, Fyno AI reads your requirement, looks up the best-fitting helper from the handlebar library, and writes the handlebar, checking its syntax along the way. You can click **Cancel** at any point.

![Fyno AI generating a handlebar](/docs/_fern-img/d09f773caed2906382cc0e554ad41bc8df4c04c18e51713f5b509eff63073d31.webp)

#### Review and copy

Fyno AI shows the generated handlebar with a sample output, so you can confirm it does what you expect.

Click **Copy** and paste it into your template.

> **Note**
>
> Always test a generated handlebar with a sample payload before publishing your template, just as you would with one you wrote yourself.

> **Check the quotes in generated handlebars**
>
> Arguments inside a handlebar must use single quotes, because double quotes can break your template, especially in emails. If a generated handlebar contains double quotes, replace them with single quotes before you use it.

### Example requirements

These examples use the [sample payload](#handlebars-in-fynos-templates) from earlier on this page.

#### Show a fallback value when a field is empty

**`Requirement`**

```text title="Requirement" wordWrap
Show members.0.city. If it's empty, show Bangalore instead.
```

**`Generated handlebar`**

```hbs title="Generated handlebar" wordWrap
{{default members.0.city 'Bangalore'}}
```

**`Output`**

```text title="Output" wordWrap
Bangalore
```

#### Show different text based on a value

**`Requirement`**

```text title="Requirement" wordWrap
If user_type is pro, show "Pro member". Otherwise, show "Standard member".
```

**`Generated handlebar`**

```hbs title="Generated handlebar" wordWrap
{{#ifEquals user_type 'pro'}}
  Pro member
{{else}}
  Standard member
{{/ifEquals}}
```

**`Output`**

```text title="Output" wordWrap
Pro member
```

#### Total a list of amounts as currency

**`Requirement`**

```text title="Requirement" wordWrap
Add up the amount of every item in investments and show it as US dollars.
```

**`Generated handlebar`**

```hbs title="Generated handlebar" wordWrap
{{formatNumber (sumAll @root 'investments.amount') 'en-US' 'style=currency, currency=USD'}}
```

**`Output`**

```text title="Output" wordWrap
$30.00
```

#### List every item in an array

**`Requirement`**

```text title="Requirement" wordWrap
List every investment as a numbered line with the company name and amount in dollars. If there's no company, show "Not known". If there are no investments, say so.
```

**`Generated handlebar`**

```hbs title="Generated handlebar" wordWrap
{{#each investments}}
  {{math @index '+' 1}}.
  {{{default this.company 'Not known'}}}
  - ${{this.amount}}
{{else}}
  No investments were made!
{{/each}}
```

**`Output`**

```text title="Output" wordWrap
1. L&T - $10

2. Not known - $20
```

### Not quite right? Regenerate with feedback

Click **Try Again** to open **Re-Generate Handlebar**. Refine your requirement and, optionally, choose what went wrong from the **Feedback** dropdown. Your feedback helps us improve Fyno AI.

Click **Generate** to try again, or **Back** to return to the previous result.

### If generation fails

If Fyno AI can't generate a handlebar, you'll see **Oops! That didn't go as planned**. Click **Try Again**, ideally with a more specific prompt. If an earlier attempt had succeeded, you can also click **View previous Handlebar** to go back to that result.

## Handlebars Builder

The [Handlebars Builder](https://hbs.fyno.io/) lets you build handlebar logic visually, without writing the syntax yourself. To open it from a template, expand **Handlebars** > **Build Your Own** in the left panel and click **Handlebars Builder**.

![](/docs/_fern-img/6ff620df2844011792568ea07b01155a3683657936d307755866240935ae983e.webp)

#### Add blocks

Add blocks from the toolbox (**Content**, **Date & Time**, **String**, **Math**, **Logic**, **Values** and **Print**) to build your logic.

#### Enter sample data

In **Input Object**, enter sample data as JSON, such as the [sample payload](#handlebars-in-fynos-templates) on this page.

#### Check the result

**Handlebar Syntax** shows the generated handlebar, and **Output Preview** shows the result for your sample data.

#### Copy the handlebar

Click **Copy** under **Handlebar Syntax** and paste the handlebar into your template.