Let's assume that the following JavaScript object is passed to a Handlebars template:
let context = { name: 'World' };
The template file itself will contain the following markup:
let source = `<div> Hello {{ name }}! </div>`
The preceding markup contains name as the HTML expression that will be interpolated by its context object.
We need to write the JavaScript method that makes it work, as follows:
let template = Handlebars.compile(source);
let output = template(context);
This output variable will contain the following HTML code:
<div> Hello World! </div>