Mustache is a fantastic simple templating engine that can be used in many different languages and frameworks.
There are several different ways of accomplishing this. Watch the video to see them in action.
You can keep your templates in separate standalone files and retrieve them with AJAX.
The templates can be stored in special template script tags in your page.
No matter which style you go with, the end result is the same.