2 <head><title>Jstemplates: Quick example</title>
3 <script src="../util.js" type="text/javascript"></script>
4 <script src="../jsevalcontext.js" type="text/javascript"></script>
5 <script src="../jstemplate.js" type="text/javascript"></script>
6 <script type="text/javascript">
7 var favdata = {title: 'Favorite Things', favs:['raindrops', 'whiskers', 'mittens']};
9 function showData(reprocess) {
10 var templateToProcess;
11 var peg = document.getElementById('peg');
13 if (!reprocess) { // Get a copy of the template:
14 templateToProcess = jstGetTemplate('t1');
15 // Clear the element to which we'll attach the template:
17 // Attach the template
18 domAppendChild(peg, templateToProcess);
20 else { // Use the copy we already have
21 templateToProcess = peg;
23 // Wrap our data in a context object:
24 var processingContext = new JsEvalContext(favdata);
26 // Process the template
27 jstProcess(processingContext, templateToProcess);
30 <link rel="stylesheet" type="text/css" href="css/maps2.deb.css"/>
32 <body onload="showData(false)">
34 The element to which our template will be attached at display-time:
39 A container to hide our template:
41 <div style="display:none">
44 This is the template div. It will be copied and attached to the div above.
47 <h1 jscontent="title"></h1>
48 <ul><li jscontent="$this" jsselect="favs"></li></ul>
54 <a href="#" onclick="favdata.favs.push('packages');showData(true);">Reprocess</a>