Binding an object to the template

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>
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.9.169