Django Template Language

This is one of the coolest features in Dojo. I like it because, just like other template patterns, you can accomplish a lot with data driven programming. Using DTL makes processing data easy and you can replace the template conditionally in code. Taking a snippet from the DojoCampus, you can see the power of using templates by reading the code – see below.

  //Load the NodeList extension for DTL

    // Retrieve the nodes (there's only one) using dojo.query
    // Apply the template, which is loaded from a remote file
      { items: ["apple", "banana", "pear"] });

An unordered list is created here from a JavaScript array

The URL (featureexplorer/Dojox/DTL/nodelist.txt) has the following content:

    {% for item in items %}
  • {{ item }}
  • {% endfor %}

You can see the code uses the text snippet to show the HTML in a “template” manner. This means we could have used a condition to show the data in a different way by pointing to another template. In this case it creates a DIV wrapper and then a list, where each entry in the array ends up being a single entry in the list.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.