如何在Odoo模板语言中使用

Mar*_*elo 4 odoo odoo-8 odoo-website

我正在尝试使用与Django相同的功能:

<div class="item {% if condition == True %}active{% endif %}">
Run Code Online (Sandbox Code Playgroud)

在Odoo我有:

<t t-foreach="list" t-as="l">
    <a t-attf-href="/downloads/{{l.id}}" class="list-group-item"><t t-esc="l.name"/></a>
</t>
Run Code Online (Sandbox Code Playgroud)

如果"c.id = cat_id",我需要附加类"active"

怎么在Odoo完成?

我正在使用:

<t t-foreach="categories" t-as="c">
    <t t-if="c.id == category_id">
    <a t-attf-href="/downloads/{{c.id}}" class="list-group-item active"><t t-esc="c.name"/></a>
    </t>
    <t t-if="c.id != category_id">
    <a t-attf-href="/downloads/{{c.id}}" class="list-group-item"><t t-esc="c.name"/></a>
    </t>
</t>
Run Code Online (Sandbox Code Playgroud)

但寻找更加蟒蛇的方式

Lud*_*mer 6

我认为QWeb模板甚至不打算成为Pythonic;)

如果你想要你可以这样做:

<a t-attf-href="/downloads/{{c.id}}" t-attf-class="list-group-item {{ 'active' if c.id == category_id else '' }}">
    <t t-esc="c.name"/>
</a>
Run Code Online (Sandbox Code Playgroud)