Changing the Handlebars extension and adding complete code to a view Express.js Handlebars

Rodrigo Figueroa
Geek Culture

--

Hi, I’m learning a lot of new things with Hanldebars templating for Express.js, and I want to share this new things

First of all, we can change the extension .handlebars to .hbs for the layout in this case we need to set the extname: ‘.hbs’ in the engine object

Example adding extname to .hbs
Example adding extname to .hbs

And it will search for the .hbs layout extension

Complete code to a view, for example, if we want to add a complete custom HTML template we need to specify the layout to null

Example setting the layout to null for the response
Example setting the layout to null for the response
Example just <h1> tag and no default layout
Example just <h1> tag and no default layout

Let’s add our own complete code

Example added a complete HTML template into a view
Example added a complete HTML template into a view
Outcome of the HTML custom template into a view
Outcome of the HTML custom template into a view
Example source code Chrome browser
Example source code Chrome browser

Conclusion

These are shortcuts to help you work with Express.js and handlebars and on top of that you can use them as a way to improve your views or layouts.

Sources

--

--

Rodrigo Figueroa
Geek Culture

I’m a Web Developer, fanatic of books and Smash Player.