How to install and configure Handlebar.js ?

devquora
devquora

Posted On: Dec 21, 2022

 

You can install and configure Handlebar.js using npm or yarn:

npm install handlebars
# or
yarn add handlebars

You can then use Handlebars using require
const Handlebars = require("handlebars");
const template = Handlebars.compile("Name: {{name}}");
console.log(template({ name: "Nils" }));

You can configure express-handlebars as our view engine:

app.engine('hbs', exphbs({
    defaultLayout: 'main',
    extname: '.hbs'
}));

app.set('view engine', 'hbs');

By default, the extension for Handlebars templates is .handlebars. But in the settings here, we've changed it to .hbs via the extreme flag because it's shorter.

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    Handlebars js Interview Questions

    Explain Handlebar.js ?

    Handlebar.js is a templating engine that is based on Mustache template language. You can install Handlebar.js by running npm install --save handlebars command....

    Handlebars js Interview Questions

    What is current stable version of Handlebar.js ?

    4.0.12 is the current stable version of HandlebarsJS...

    Handlebars js Interview Questions

    Explain Bower ?

    Bower is a package manager for the web. It is used to install libraries, assets, and utilities. You can install bower via npm by running npm install bower command....