Chapter 19. Templates: filling placeholders with data
This chapter covers
- Replacing one string with another
- Repeating code with while loops
- Using templates to separate HTML from JavaScript
- Embedding templates in web pages
- Transforming one array into another with map
You want your websites to be easy to navigate and a pleasure to use. Their designs should consider what content to include on each page, its accessibility and usability, the look and feel, and the overall user experience. Members of your team, building and maintaining a site, will have different strengths; even as a team of one, it makes sense to focus on different aspects of a site at different times.
Get Programming with JavaScript has favored a modular approach to developing applications, and you’ve seen that although there may be more pieces to manage, the management of each piece is simpler, more flexible, and more focused. But in moving from pure JavaScript in part 2 to JavaScript and HTML in part 3, there has been an unwelcome crossing of the streams. You now have views that mix data and JavaScript with HTML to produce their output (see chapter 17—or better yet, read on):