I picked up this nifty way of templating HTML code for JavaScript while working at Monkey Quest and haven’t looked back. The idea here is to separate your design from your code. This is particularly useful when you are adding content to your site after the initial rendering. Data can be fed in from a number of sources and added to a page using a template.
This is a useful tidbit of code to have until PHP adds this feature into their MongoDB extension. I stumbled on an example on Stack Overflow illustration showing how to do this and rewrote it in what I think is a slightly more modern way that does the same thing.