Rendering HTML Code with DJANGO and DOJO

19 Jul

One of the things that I like about dojo is the django rendering engine. It provides an easy way to build HTML Templates and let you render values form a json object. The following example of a template is used to loop through a json array response.

{% for entry in feed.entries%}
<div style=”height: auto;”>
<a target=”_blank” href=”{{}}”>{{entry.title}}</a>

This code is used in the dojo widget:

dojo.declare(“xptrss.list.feedcontroller”, [ dijit._Widget, dojox.dtl._Templated ], {
feed : null,
templateString : dojo.cache(“xptrss.list.feedcontroller”,    “../../html/rssTemplate.html”),
targetid: null,
postCreate: function() {
var mySelf = this;
var xhrArgs = {
url : mySelf.proxyurl,
handleAs : “json”,
preventCache : true,
load : function(data) {
mySelf.feed = data;
mySelf.render(); +”_feedLoader”, {
display : “none”
error : function(error) {

var deferred = dojo.xhrGet(xhrArgs);


With the statement  templateString : dojo.cache(“xptrss.list.feedcontroller”,    “../../html/rssTemplate.html”) the html will be loaded. The “postCreation()” handles the loading of the values. With “mySelf.render()” the loaded JSON object will be applied to the HTML Template and the django engine loops through all entries and applies the code between {% for …. } {%endfor%} for each entry.

But what if an element in an entry (like the content value) is pure HTML Code?

The django engine is so clever and escapse all content correct, but we need the content unescaped in this particular case. The statement  {{entry.content|safe}} does the trick!

This is code from our new project XPages Toolkit.

Leave a comment

Posted by on July 19, 2013 in Domino, Java, XPages


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: