Answer the question
In order to leave comments, you need to log in
How to make Erlydtl render a list of entries into a template?
For example:
-record(usr,{name,email}).
...
Usr1 = #usr{name="John", email="[email protected]"},
Usr2 = #usr{name="Jane", email="[email protected]"},
Usr3 = #usr{name="Alex", email="[email protected]"},
{ok, Result} = template_dtl:render([{users, [Usr1, Usr2, Usr3]}]),
...
{% block content %}
{% for user in users %}
<a href="mailto:{{user.email}}">Send mail to {{user.name}}</a>
{% endfor %}
{% endblock %}
Answer the question
In order to leave comments, you need to log in
Form the context and send it to render
Source = "My name is {{ name }}.",
{ok, Tpl} = dtl_template:new(Source),
Ctx = dtl_context:new([
{name, "Lawrence"}
]),
{ok, <<"My name is Lawrence">>} = dtl_template:render(Tpl, Ctx).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question