| 1 | <html> |
| 2 | <head> |
| 3 | <title>Demo using dojox.dtl._Templated</title> |
| 4 | <script type="text/javascript" src="../../../dojo/dojo.js" |
| 5 | djConfig="async: true, isDebug: true, parseOnLoad: true"></script> |
| 6 | <script type="text/javascript"> |
| 7 | require(['dojox/dtl/ext-dojo/NodeList', |
| 8 | 'dojox/dtl/Context', |
| 9 | 'dojo/query', |
| 10 | 'dojo/dom', |
| 11 | 'dojo/parser', |
| 12 | 'dojo/domReady!', |
| 13 | 'dojox/dtl/tag/logic'], |
| 14 | function(NodeList, Context, query, dom){ |
| 15 | |
| 16 | // First, look at the NodeList extension |
| 17 | query(".fruit").dtl(require.toUrl("dojox/dtl/demos/templates/nodelist.html"), { items: ["apple", "banana", "pear"] }); |
| 18 | |
| 19 | query(".fruit2").dtl("<div><ul>{% for item in items %}<li>{{ item }}</li>{% endfor %}</ul></div", { items: ["apple", "banana", "pear"] }); |
| 20 | |
| 21 | // Now, create a real template object |
| 22 | var tpl = new dojox.dtl.Template(require.toUrl("dojox/dtl/demos/templates/nodelist.html")); |
| 23 | |
| 24 | // And test its update function with a dojo.query |
| 25 | tpl.update(query(".update"), require.toUrl("dojox/dtl/demos/json/fruit.json")); |
| 26 | |
| 27 | setTimeout(function(){ |
| 28 | // And now test it with an ID reference |
| 29 | tpl.update("updateId", require.toUrl("dojox/dtl/demos/json/morefruit.json")); |
| 30 | // And throw in a standard rendering just for fun |
| 31 | dom.byId("updateId2").innerHTML = tpl.render(new dojox.dtl.Context({ items: ["pineapple", "orange", "tomato"] })); |
| 32 | }, 5000); |
| 33 | }); |
| 34 | </script> |
| 35 | </head> |
| 36 | <body> |
| 37 | <div class="fruit"></div> |
| 38 | <div class="fruit2"></div> |
| 39 | <div class="update" id="updateId"></div> |
| 40 | <div class="update" id="updateId2"></div> |
| 41 | </body> |
| 42 | </html> |