Tuesday, March 4th, 2008

Dojo and Django templates on the server side with Jaxer

Category: Aptana, Dojo

Yesterday we posted about Dojo and AIR and how the framework could be well suited for certain desktop applications.

Today we have Kriz Zyp talking about their Jaxer support and how you can use the Django template language, that Dojo recently added, to once again do its thing on the server side.

Kris tells us more:

  1. <script runat="both">
  2. djConfig = {baseUrl:"/dojo/",usePlainJson: true, parseOnLoad: true};
  3. </script>
  4. <script runat="both" type="text/javascript" src="../../../dojo/dojo.js"></script>
  5. <script runat="server">
  6. dojo.require("dojo.jaxer");
  7. ...
  8. </script>

Once this is done, Dojo should load in Jaxer, and you can utilize the library capabilities of the Dojo Toolkit on the server side. In particular, you can now use the DTL renderer as you would on the browser. The DTL renderer can take templates written using Django template language and render the templates based upon JSON data. If you are running Jaxer, you can view a demonstration of DTL rendering on the server by loading /dojox/dtl/demos/demo_Templated_Jaxer.html (make sure the Dojo Toolkit base URL is correct).

By using Jaxer’s capability to allow scripts to execute on both the client and server, we can utilize our Dojo Toolkit in both environments. On the server we can utilize many of the Dojo Toolkit’s features such as functional language features, math libraries, cryptography, dates, encoding, and more to improve development speed and code quality. We can use the same powerful features and idioms in both the browser and the server. An example of a practical way to use the Dojo Toolkit in both environments is to utilize the DTL renderer as described above to generate HTML on the server, and then use the Dojo Toolkit’s Ajax capabilities to dynamically update the page once it’s on the browser. For example: we could use the DTL renderer to display the comments in a blog, dynamically add any new comment the user makes at the end of the list of comments, and then send the comment to the server using Ajax.

It is important to note that Jaxer is not capable of transferring the programatically set event handlers for widgets—it can only send the static HTML to the browser. This means you can use DTL as a templating engine to create HTML on the server, but the Dojo Toolkit client side widgets are still necessary if you want to use interactive widgets on the browser.

Posted by Dion Almaer at 7:58 am
Comment here

+++--
3.8 rating from 21 votes

Comments Here »

Comments feed TrackBack URI

Leave a comment

You must be logged in to post a comment.