Handlebars
A templating language used to generate HTML code.
Extra info
One thing I forgot in the lecture was that when you use the #each
helper, the context is changed to the value you are iterating over. You can use ../
in the beginning to reference the parent context. Example:
Context:
{
isLoggedIn: true,
humans: [
{id: 1, name: "Alice"},
{id: 2, name: "Bob"}
]
}
Template:
Generated HTML code:
Extra info
One thing I forgot in the lecture was that when you use the #each
helper to iterate over primitive values (strings, numbers, booleans, etc.), you can use this
to reference the value you are iterating over.
Context:
{
names: [
"Alice",
"Bob"
]
}
Template:
Generated HTML code:
Lecture material
Recommended reading
- Handlebars' Language Guide
- tryhandlebarsjs.com
- Use it for practice and to see a lot of examples.