<!DOCTYPE html>
<html>
<head>
	<script src="http://code.jquery.com/jquery.js" type="text/javascript"></script>
	<script src="../../../jsrender.js" type="text/javascript"></script>
	<link href="../../resources/demos.css" rel="stylesheet" type="text/css" />

	<link href="../../resources/movielist.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="subhead"><< <a href="../variants.html">JsRender Demos: Variants</a></div>

<h3>Compiling template objects from strings</h3>

<div class="subhead"> Variant of <a href="../../step-by-step/02_compiling-named-templates-from-strings.html">Compiling named templates sample</a></div><br />

<button id="switchBtn">Show full details</button><br/>
<br />
<table>
	<tbody id="movieList"></tbody>
</table>

<script type="text/javascript">
	var movies = [
		{ name: "The Red Violin", releaseYear: "1998", director: "François Girard" },
		{ name: "Eyes Wide Shut", releaseYear: "1999", director: "Stanley Kubrick" },
		{ name: "The Inheritance", releaseYear: "1976", director: "Mauro Bolognini" }
	];

	/* Compile markup as template objects */
	var titleTemplate = $.templates( "<tr><td colspan=3>{{>name}}</td></tr>" ),
		detailTemplate = $.templates( "<tr><td>{{>name}}</td><td>Released: {{>releaseYear}}</td><td>director: {{>director}}</td></tr>" ),
		details = true;

	function switchTemplates() {
		var html;

		details = !details;

		/* Render using the other compiled template */
		if ( details ) {
			$( this ).text( "Show titles only" );
			html = detailTemplate.render( movies );
		} else {
			$( this ).text( "Show full details" );
			html = titleTemplate.render( movies );
		}
		$( "#movieList" ).html( html );
	}

	$( "#switchBtn" ).click( switchTemplates );

	switchTemplates();
</script>

</body>
</html>