<!DOCTYPE html>
<html>
<head>
	<script src="/usr/share/javascript/jsquery/jquery.min.js" type="text/javascript"></script>
	<script src="..//usr/share/javascript/jsrender/jsrender.min.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>Template composition. Passing in template objects as the contextual template parameters.</h3>

<div class="subhead"> Variant of <a href="../../step-by-step/06_template-composition.html">template composition sample</a></div><br />

<script id="movieTemplate" type="text/x-jsrender">
	<tr>
		<td>{{>title}}</td>
		<td>
			{{for languages tmpl=~columnTemplate/}}
		</td>
		<td>
			{{for languages tmpl=tmpl/}}
		</td>
		<td>
			{{for languages tmpl=~conditionalTemplate/}}
		</td>
	</tr>
</script>

<script id="columnTemplate" type="text/x-jsrender">
	<div>
		<em>{{>name}}</em>
	</div>
</script>

<script id="rowTemplate" type="text/x-jsrender">
	<span>
		<b>{{>name}}</b>
	</span>
</script>

<script id="conditionalTemplate" type="text/x-jsrender">
	{{if name.charAt(0)==='E' tmpl=~rowTemplate}}
	{{else tmpl=~columnTemplate}}
	{{/if}}
</script>

<table>
	<thead><tr><th>Synopsis</th><th>Fixed Template</th><th>Template specified in data</th><th>Conditional Template</th></tr></thead>
	<tbody id="movieList"></tbody>
</table>

<script type="text/javascript">

	var movies = [
		{
			title: "Meet Joe Black",
			languages: [
				{ name: "English" },
				{ name: "French" }
			],
			tmpl: "#columnTemplate"
		},
		{
			title: "Eyes Wide Shut",
			languages: [
				{ name: "French" },
				{ name: "Esperanto" },
				{ name: "Spanish" }
			],
			tmpl: "#rowTemplate"
		},
		{
			title: "The Inheritance",
			languages: [
				{ name: "English" },
				{ name: "German" }
			],
			tmpl: "#columnTemplate"
		}
	];

	var myTemplates = {
		movieTemplate: $.templates("#movieTemplate"),
		columnTemplate: $.templates("#columnTemplate"),
		rowTemplate: $.templates("#rowTemplate"),
		conditionalTemplate: $.templates("#conditionalTemplate")
	};

	$( "#movieList" ).html(
		myTemplates.movieTemplate.render( movies, myTemplates )
	);

</script>

</body>
</html>


