Templates en HTML5

Una de las características de AngularJS es el uso de templates. HTML5 tiene algo parecido aunque no tan potente, tiene un elemento template. La definición dice:

The template element is used to declare fragments of HTML that can be cloned and inserted in the document by script.

Y un ejemplo de uso:

<!DOCTYPE html>
<title>Cat data</title>
// Data is hard-coded here, but could come from the server
var data = [
{ name: ‘Pillar’, color: ‘Ticked Tabby’, sex: ‘Female (neutered)’, legs: 3 },
{ name: ‘Hedral’, color: ‘Tuxedo’, sex: ‘Male (neutered)’, legs: 4 },
<th>Name <th>Color <th>Sex <th>Legs
<template id=”row”>
var template = document.querySelector(‘#row’);
for (var i = 0; i < data.length; i += 1) {
var cat = data[i];
var clone = template.content.cloneNode(true);
var cells = clone.querySelectorAll(‘td’);
cells[0].textContent = cat.name;
cells[1].textContent = cat.color;
cells[2].textContent = cat.sex;
cells[3].textContent = cat.legs;