Is there a way to nest HTML5 < template > tags inside each other?
Looking for an easy way to update my page with universal code so that every page does not require a lot of JS to function.
For instance the following code:
<!DOCTYPE html>
<html>
<head>
<title>Test Page</title>
</head>
<body>
<a href="#" class="link">Load Template</a><br>
<template id="profileview">
<h1>Employee</h1>
<template id="employeename">
<div>
<label for="FirstName">First Name:</label>
<input type="text" name="FirstName" id="FirstName" value="">
</div>
<div>
<label for="MiddleInitial">Middle Initial:</label>
<input type="text" name="MiddleInitial" id="MiddleInitial" value="">
</div>
<div>
<label for="LastName">Last Name:</label>
<input type="text" name="LastName" id="LastName" value="">
</div>
</template>
</template>
<script src="/media/js/jquery/jquery-1.9.1.js"></script>
</body>
JS file:
$('.link').click(function(event) {
event.preventDefault();
$.ajax({
url: '/codes/html5/template.json.php',
dataType: 'json'
}).done(function(result) {
var body = $('body');
$.each(result.templates, function(i, t) {
var template = document.querySelector('#'+t.name);
if (t.subtemplates) {
$.each(t.subtemplates, function(j, t2) {
// subtemplate processing code here
});
}
var clone = document.importNode(template.content, true);
body.append(clone);
});
});
});
JSON file:
{
"templates" : [
{
"name" : "profileview",
"subtemplates" : [
{
"name" : "employeename"
}
]
}
]
}