Skip to content
Dmitry Klionsky edited this page Apr 11, 2016 · 10 revisions

Introduction

ErlyDTL is an Erlang implementation of the Django Template Language. The erlydtl module compiles Django Template source code into Erlang bytecode. The compiled template has a render function that takes a list of variables and returns a fully rendered document.

The project is stable and mostly complete. Most tags and all filters have been implemented. See Tags and Filters for a list of supported features.

Support

Basic example illustrating the syntax

An ErlyDTL template is a text file (e.g.: a HTML or CSS file) containing variables to control the runtime template content, tags to control the runtime template logic and comments, which get filtered out.

Template file welcome.html:

Welcome back, {{ name }}!

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

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

Erlang code:

erlydtl:compile("/path/to/welcome.html", welcome_template),
welcome_template:render([
    {name, "Johnny"},
    {friends, [<<"Frankie Lee">>, <<"Judas Priest">>]},
    {primes, [1, 2, "3", <<"5">>]}
]).

Result:

Welcome back, Johnny!

You have 2 friends: Frankie Lee, Judas Priest

Have some primes:
1
2
3
5

ErlyDTL reference

See the Overview for complete usage.

Tags and Filters

See Tags and Filters for a up-to-date list of the Django tags & filters that ErlyDTL supports.

Other features

  • Variables can optionally be pre-set at template compilation, which is useful for stuff which doesn't change often. These variables get pre-rendered as much as possible at compilation time for maximum performance.
  • Optional recompilation: skip unnecessary compile if a compiled template exists already and the template source checksum has not changed.
  • Templates accept variables as property list, dict and gb_tree and the actual values can be numbers or strings (lists or binaries).
  • Variables, Tags and Comments can be wrapped with HTML comments (<!--, -->) for a possibly better integration with certain HTML editors / browser previews.
  • Templates need not live on the local file system; you can write your own "reader" function, e.g. to read templates from network storage such as Amazon S3.

Requirements Build Status_

Erlang R15B02 or newer (except R16B03, syntax tools is broken in that version).

Check up-to-date status for each supported release on Travis CI.

ToDo

Check the erlydtl issues for up-to-date info.

Clone this wiki locally