Go to page content



ErlyDTL is an Erlang implementation of the Django Template Language.

The basis of the Zotonic template compiler is forked version of ErlyDTL.

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 a Zotonic context and returns a fully rendered document.

We have made numerous adaptations to the standard ErlyDTL.  Check the documentation for the template tags and template filters to get a complete overview.

Amongst other changes we added:

  • {% url %} tag to fetch the url of a resource.  It takes a dispatch list.
  • {% image %} tag to generate an <img /> tag for a media item.
  • {% image_url %} tag shows the url of the corresponding {% image %} tag.
  • {% media %} as image but also handles embed codes for inline movies and other html objects.
  • Support for any scomp (screen component) to be called as if it was a Django template tag.
  • {% empty %} for showing something when a foreach loop is empty.
  • Or and and if expressions.
  • {% cache %} block for caching partial templates.
  • {% include %} with extra parameters for local bindings.
  • {% print %} to dump a complete datastructure as output in the template.
  • {% lib %} to combine javascript or css files in a single <link/> or <script /> tag.
  • Support for list values using Erlang list notation: [a, b, c]
  • Support for tuple values consisting of an atom and a property list: {some_name a=1 b=2}
  • Support for generating unique ids for each template, for example: <div id="{{ #myid }}">
  • Translation of strings using an "_" in front of strings:  _"translate me"
  • Many filters are added, for example: eq_day,ne_day, date_range, default_if_none, is_defined, slugify, striptags, member and yesno.
  • Variable lookup knows about the Zotonic context and assumes that an integer is the id of a database resource.

Besides this we made some extra changes:

  • Includes with caching parameters (for example vary and maxage) will cache their contents (handled by the scomp include).
  • The generated render function takes a Zotonic context as the third parameter: render(Template, Vars, Context)
  • Templates are only compiled into memory, no beam files are generated.  This prevents problems when internal template logic is changed between versions.
  • Template modification checks are done differently, a global reset counter is used and stored in the compiled template to force recompilation of templates when needed and the modification check for included templates is simplified.