| 1 | <html> |
| 2 | <head> |
| 3 | <title>Demo using dojox.dtl._Templated</title> |
| 4 | <script runat="server"> |
| 5 | djConfig = {baseUrl:"/dojo/",usePlainJson: true, parseOnLoad: true}; |
| 6 | </script> |
| 7 | <script runat="server" type="text/javascript" src="../../../dojo/dojo.js"></script> |
| 8 | <script runat="server" type="text/javascript"> |
| 9 | dojo.require("dojo.jaxer"); |
| 10 | dojo.require("dijit.dijit"); |
| 11 | dojo.require("dojox.dtl._Templated"); |
| 12 | dojo.require("dojo.parser"); |
| 13 | |
| 14 | dojo.declare("Fruit", [dijit._Widget, dojox.dtl._Templated], { |
| 15 | oldRepl: "Fruit: ", |
| 16 | _dijitTemplateCompat: true, |
| 17 | items: ["apple", "banana", "orange"], |
| 18 | keyUp: function(e){ |
| 19 | if(e.keyCode == dojo.keys.ENTER){ |
| 20 | var i = dojo.indexOf(this.items, e.target.value); |
| 21 | if(i != -1){ |
| 22 | this.items.splice(i, 1); |
| 23 | }else{ |
| 24 | this.items.push(e.target.value); |
| 25 | } |
| 26 | e.target.value = ""; |
| 27 | this.render(); |
| 28 | dojo.query("input", this.domNode).forEach("item.focus();"); |
| 29 | } |
| 30 | }, |
| 31 | templateString: '<div><input dojoAttachEvent="onkeyup: keyUp"><ul>{% for item in items %}<li>${oldRepl} {{ item }}</li>{% endfor %}</ul></div>' |
| 32 | }); |
| 33 | </script> |
| 34 | </head> |
| 35 | <body> |
| 36 | <h1>Using Dojo's Django Template language on Jaxer</h1> |
| 37 | <div> |
| 38 | Aptana's Jaxer is server side JavaScript (SSJS) server. With some modifications to |
| 39 | a web page, Dojo can be run on the server. With Dojo running on the server, you can |
| 40 | utilize the Dojo's Django Template library rendering engine to do templating within |
| 41 | Jaxer. The latest build of Dojo includes some patches to properly work with Jaxer, |
| 42 | so you need a build of Dojo later than 2/18/08 to work with Jaxer. Next, the |
| 43 | following modifications to your page are needed to run Jaxer: |
| 44 | <ul> |
| 45 | <li> |
| 46 | You must explicitly set the base url of the Dojo library. Jaxer does not provide |
| 47 | the ability for Dojo to auto-detect the base url as it can in other environments. |
| 48 | Therefore you must declare the base url with the djConfig global variable: |
| 49 | <pre> |
| 50 | <script runat="server"> |
| 51 | djConfig = {baseUrl:"/dojo/", // use the base path of dojo here |
| 52 | usePlainJson: true, parseOnLoad: true}; |
| 53 | </script> |
| 54 | </pre> |
| 55 | </li> |
| 56 | <li> |
| 57 | Next, you must add the runat attribute with a value of "server" to all of the script |
| 58 | tags that you want executed on the server. Your script tags should look like: |
| 59 | <pre> |
| 60 | <script runat="server" type="text/javascript" src="../../../dojo/dojo.js"></script> |
| 61 | </pre> |
| 62 | </li> |
| 63 | <li> |
| 64 | Last, you must dojo.require("dojo.jaxer") with a script tag. This should immediately |
| 65 | follow the declaration of dojo.js: |
| 66 | <pre> |
| 67 | <script runat="server" type="text/javascript" src="../../../dojo/dojo.js"></script> |
| 68 | <script runat="server" type="text/javascript">dojo.require("dojo.jaxer");</script> |
| 69 | </pre> |
| 70 | </li> |
| 71 | </ul> |
| 72 | </div> |
| 73 | <p> |
| 74 | Once this is done, Dojo should load in Jaxer, and you can utilize the library capabilities of |
| 75 | Dojo. In particular, you can now use DTL renderer as you would on |
| 76 | the browser. If you are running this in Jaxer, below should be a working demonstration of |
| 77 | a template that is rendered on the server. |
| 78 | </p> |
| 79 | <div dojoType="Fruit"></div> |
| 80 | <p> |
| 81 | It is important to note that Jaxer is not capable of transferring the programmaticaly set |
| 82 | event handlers for widgets, it can only send the static HTML to the browser. This means |
| 83 | you can use DTL as a templating engine to create HTML on the server, but Dojo client side widgets |
| 84 | are still necessary if you want to use interactive widgets on the browser. |
| 85 | </p> |
| 86 | </body> |
| 87 | </html> |