erlydtl if in

11 views
Skip to first unread message

TX

unread,
Aug 29, 2016, 1:42:49 AM8/29/16
to erlydtl-users
Hi,

I read the Django template documentation about if in, it said:

{% if "hello" in greetings %}
  If greetings is a list or set, one element of which is the string
  "hello", this will appear.
{% endif %}

I am using Chicagoboss,

in my model file role.erl, I have:
-module(role, [Id, Roletype]).
-compile(export_all).

in my controller, I have:
Roles = boss_db:find(role, []),
    {ok, [{roles, Roles}]};

in my view page, I have:
 <ul>
             {% for role in roles %}
             <li>{ role.roletype }</li>
             {% endfor %}
  </ul>

{% if "salesmanager" in roles %}
       <p>sales</p>
{% endif %}

I added salesmanager and some more roletypes into the database and they can be displayed by role.roletype, but the "if "sales" in roles" do not show sales as it supposed to be, I have replaced roles by Roles, roles.roletype, role.roletype, roletype, roletypes, not working.

I can't find a similar situation online, can anyone advise me what is wrong?

Thank you.

Nuku Ameyibor

unread,
Aug 29, 2016, 1:32:31 PM8/29/16
to ErlyDTL Users, 23161...@qq.com
what datatype is your roles variable .
the example below is for a list or set datatype but seems your data is more of a list where each item is  a dictionary/gbtree or something else .
so it cant seem to find the item .
try this

   {% for role in roles %}
        {% if role.roletype == "salesmanager" %}

              <p>sales</p>
        {% endif %}
  {% endfor %}

TX

unread,
Aug 29, 2016, 7:51:23 PM8/29/16
to erlydtl-users
yes, that's the problem.

Thank you.


------------------ 原始邮件 ------------------
发件人: "Nuku Ameyibor";<nay...@gmail.com>;
发送时间: 2016年8月30日(星期二) 凌晨1:32
收件人: "ErlyDTL Users"<erlydt...@googlegroups.com>;
抄送: "TX"<23161...@qq.com>;
主题: Re: erlydtl if in
--
You received this message because you are subscribed to the Google Groups "ErlyDTL Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to erlydtl-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages