如果使用Odoo模板语言,如何使用 [英] How to use if in Odoo template language

查看:82
本文介绍了如果使用Odoo模板语言,如何使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to use the same functionality as in Django:

<div class="item {% if condition == True %}active{% endif %}">

在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>

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

And I need to append class "active" if "c.id = cat_id"

在Odoo中如何完成?

how it's done in 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>

但是正在寻找更Python化的方式

But searching for a more pythonic way

推荐答案

我认为QWeb模板甚至都不打算是Pythonic的;)

I don't think QWeb templates are even intended to be Pythonic ;)

您可以根据需要执行以下操作:

You can do this if you want:

<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>

这篇关于如果使用Odoo模板语言,如何使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆