ErlyDTL Templates

Available from 1.3 rev. 292

Abstract

Elang Web is now capable of handling templates written in Django Template Library. To achieve this we used an ErlyDTL Erlang implementation of the DTL language. ErlyDTL is described in more detail on the ErlyDTL @googlecode

The library is stable and most of the original DTL tags and filters have already been implemented. Here is the list of them.

Running

In order to be able to use DTL in your project the only thing you have to do is to specify the expander of the templates in the config/project.conf file. The wpart_xs expander is taken for default to achieve backwards compatibility. To change it to ErlyDTL you have to add the following tuple to the config/project.conf file:

{template_expander, TEMPLATE_EXPANDER}.

where TEMPLATE_EXPANDER = wpart_xs | erlydtl_expander

Examples

Controller:

test(_) ->
    wpart:fset("name", "Joe"),
    wpart:fset("friends", ["Robert", "Mike"]),
    wpart:fset("primes", [1, 2, "3", <<"5">>]),

    {template, "dtl/test.html"}.

View:

Welcome back, {{ name }}!

You have {{ friends|length }} friends: {{ friends|join:", " }}

Have some primes:
{# this is exciting #}
{% for i in primes %}
{{ i }}
{% endfor %}

More examples can be found in on the ErlyDTL page.

ErlyDTL (last edited 2009-07-29 10:45:22 by insane)