1

How is it possible to extend "erlydtl"?

I really like django templates, and the way the template language can be extended. For example, I like the extensions such as "sekizai".

It is possible to have custom tag modules for erlydtl. But how do I add support for more complex tags such as provided by sekizai?

In django, using sekizai I can do following (taken from sekizai documentation).

{% render_block "css" %}

And add following to add to the above block

{% addtoblock "css" %}
<link href="/media/css/stylesheet.css" media="screen" rel="stylesheet" type="text/css" />
{% endaddtoblock %}

And this will add the contents at the place where {% render_block %} is called.

Yogesh Sajanikar
  • 1,086
  • 7
  • 19

1 Answers1

0

You need to write your own module and define functions that are called and provide the data for your template tags.

Example:

File perc_filter.erl:

-module(perc_filter).
-export([percentage/2]).

percentage(Input, Whole) when is_integer(Input), is_integer(Whole) ->
    [Result] = io_lib:format("~.2f", [Input / Whole * 100]),
     Result.

In template:

{{ x|percentage:1000 }}
P_A
  • 1,804
  • 1
  • 19
  • 33
  • Writing tag module is easy. The main problem here is that the template tag "addtoblock" should add something to already existing tag "render_block". And I do not know how to do this. – Yogesh Sajanikar Oct 23 '13 at 11:04