Skip to content

How to use Handlebars

Installation

Install Handlebars with the following commands.

In a terminal, execute the following command(s).
1
2
3
npm install --save hbs

npm install --save-dev @types/hbs

Common tasks

Add a custom helper

Register a new helper with Handlebars.

1
2
3
import { handlebars } from 'hbs';

handlebars.registerHelper('eq', (v1, v2) => v1 === v2);

Use the helper in the template.

1
2
3
{{#if (eq "v1" "v2")}}
  <div>show me</div>
{{/if}}

These explanations are related to the current item (in alphabetical order).

None at the moment.

Resources and alternatives

These resources and alternatives are related to the current item (in alphabetical order).

None at the moment.