Home
Run

Demo: Using {{if}} and {{else}} to render conditional sections.

SynopsisTitle

Data:

var movies = [
	{
		Title: "Meet Joe Black",
		Languages: "English and French",
		Subtitles: "English"
	},
	{
		Title: "Eyes Wide Shut",
		Subtitles: "French and Spanish"
	},
	{
		Title: "The Mighty"
	}
];

HTML:

<script id="movieTemplate" type="text/x-jquery-tmpl">
	<tr>
		<td>${Title}</td>
		<td>
			{{if Languages}}
				Alternative languages: <em>${Languages}</em>.
			{{else Subtitles}}
				Original language only... <br/>Subtitles in <em>${Subtitles}</em>.
			{{else}}
				Original version only, without subtitles.
			{{/if}}
		</td>
	</tr>
</script>