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):

var html = "<h3>" + movie.title + "</h3>";
html += "<p>" + movie.summary + "</p>";

19.1. Building a news page—breaking news

 
 
 

19.2. Replacing one string with another

 

19.3. While loops—replacing a string multiple times

 
 
 
 

19.4. Automating placeholder replacement for templates

 
 

19.5. Building a news page—news just in

 
 
 
 

19.6. The Crypt—improving the views

 
 

19.7. Summary

 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest