<!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>
<a href="../demos.html">JsRender Demos</a><br />

<h3>To pass an array to a "layout template" - which includes headers or footers,<br />
as well as the rendered items - wrap the array in an array...</h3>

<div class="subhead">Top-level layout:</div>
<pre>
$( "#movieList" ).html(
    // Wrap movies array in an array
    $("#movieTemplate").render( [movies] )
);

Template:

   header
   {{for #data}}
      item
   {{/for}}
   footer
</pre>

<div class="subhead">Nested layout:</div>
<pre>
{{for [languages]}}
    header
    {{for #data}}
        item
    {{/for}}
    footer
{{/for}}
</pre>

<!--================ Demo ================-->

<script id="movieTemplate" type="text/x-jsrender">
	<thead>
		<tr><th colspan="2">{{:length}} movies available:</th></tr>
		<tr><th>Title</th><th>Languages</th></tr>
	</thead>
	<tbody>
		{{for #data}}
			<tr>
				<td>{{>title}}</td>
				<td>
					{{for [languages]}}
						<div>
							{{if #data}}
								<strong>{{:length}}</strong> languages available:
								{{for #data}}
									<em>{{>name}}</em>
								{{/for}}
							{{else}}
								Original version only
							{{/if}}
						</div>
						<div>
							{{if #data}}
								Additional languages also in stock
							{{/if}}
						</div>
					{{/for}}
				</td>
			</tr>
		{{/for}}
	<tbody>
</script>

<table id="movieList"></table>

<script type="text/javascript">

	var movies = [
		{
			title: "Meet Joe Black"
		},
		{
			title: "Eyes Wide Shut",
			languages: [
				{ name: "French" },
				{ name: "Mandarin" },
				{ name: "Spanish" }
			]
		},
		{
			title: "The Inheritance",
			languages: [
				{ name: "English" },
				{ name: "Russian" }
			]
		}
	];
	$( "#movieList" ).html(
		// Wrap movies array in an array
		$( "#movieTemplate" ).render( [movies] )
	);
</script>

</body>
</html>


