Chapter 3. Working with templates
This chapter covers
- Creating templates
- Using Meteor’s default templating syntax
- Organizing JavaScript and HTML
- Using event maps to make templates interactive
- Understanding the template life cycle
Everything your web browser renders is HTML eventually. If you open any website in source view you’ll find that each page has hundreds of lines of HTML. Not only is writing everything by hand tedious, error-prone, and highly inefficient, it’s also impossible when you’re working with web applications because much of the content is dynamic and you can’t know in advance what exact code needs to be rendered.
Templates allow you to define blocks of HTML that can be reused as often as you like. As a result, you have to write less code, and your code is easier to read and much simpler to maintain.
In this chapter, you’ll learn how to write templates and what you can do with them. We’ll first take a look at Blaze, Meteor’s reactive UI library, and Spacebars, its default templating language.