Basic Template

The most basic example of creating compiling and inserting a handlebars template that I could think of.

by Christopher McCulloh

HTML

<script src="//cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.3.0/handlebars.js"></script>
	<!-- inline HTML template -->
	<script id="sample-template" type="text/x-handlebars-template">
		<!-- template html goes here -->
		Hello World.
	</script>
	<div id="target"><!-- Template results whill appear here --></div>

JavaScript

var templateSource = $('#sample-template').html();
	var template = Handlebars.compile(templateSource);
	var html = template();
	$('#target').html(html);