Creating External Templates

If you want to use the same template in multiple pages then it makes sense to create an external template. In other words, you can place a template in a separate file than the page that contains the template.

Here’s how you can declare a Template control so that it references an external template file. Notice that the following template includes a href option that points to a file named productTemplate.html.

<!-- Template --><div id="tmplProduct"    data-win-control="WinJS.Binding.Template"    data-win-options="{        href: 'productTemplate.html'    }"></div>

The productTemplate.html contains the product template and it looks like this:

<div class="product"> ...

Get Windows® 8.1 Apps with HTML5 and JavaScript Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.