5.5 Advanced Templating

A piece of code that may be reused as one part of another hbs.

hbs.registerPartials(__dirname + '/views/partials')

Setup Partials
Create a folder called Partials.
In that folder, we create footer.hbs which contains

<p>Copyright {{currentYear}}</p>

And we now can use this partial by
{{> footer}}


{{> footer}}

To allow nodemon refresh according to more files
nodemon server.js -e js,hbs
-e: extensions

HBS Helper

hbs.registerHelper('getCurrentYear', ()=>{
return new Date().getFullYear();

Now, to use this helper

<p>Created by Jude Gao - Copyright {{getCurrentYear}}</p>

Note: HBS will first search for helpers. If not found, it will then search for injections.

Helpers with Argument Passing

hbs.registerHelper('screamIt', (text)=>{
return text.toUpperCase();

<p>{{screamIt welcomeMessage}}</p>