Odoo Help


QWeb expressions if-conditions etc

Franz Palfrader
on 8/14/14, 12:21 PM 39,235 views

Where can I find basic expression, if-conditions etc.?

e.g. show prices after Login:

t-if="website.user_id != user_id" ...

and is how is "else" to compile?


It should work like this:

<t t-if="item.footer">
<span t-field="item.bank_name"/>
<span t-field="item.acc_number"/>

If you want to check for False condition:

<t t-if="not item.footer">




| 4 3 8
Delhi, India

Nothing to say .... :)

On 8/23/15, 10:14 PM

Stefan Reisich is correct for a simple condition but it won't work if it is little complex condition like in for loop it would fail

<span t-foreach="l.tax_id" t-as="t">
<span t-if="t.domain=='ipi'"><t t-esc="t.amount" /></span> <span t-if="not t.domain=='ipi'"><t t-esc="0.00" /></span>

The above code will print "0.00" as many times as first condition fails but we would want to print that single time. So I did a workaround using a variable and set its value and print value outside for loop. eg:

<t t-set= "amount" t-value="0.00" ></t> 
<span t-foreach="l.tax_id" t-as="t">
<span t-if="t.domain=='ipi'"><t t-set= "amount" t-value="t.amount" /></span>
</span> <span t-esc="'%.2f'%(amount * 100)"/>

So what above code does is, it sets value of amount variable to "0.00" and checks for condition in for loop, it it is found correct, it resets value of "amount" variable and finally we use this variable outside for loop.

It works great!!



Stefan Reisich

--Stefan Reisich--
Rove.design GmbH
| 7 7 8
Pfungstadt, Germany
--Stefan Reisich--

Stefan Reisich
On 10/6/14, 6:34 AM

From https://www.odoo.com/documentation/8.0/howtos/web.html#the-qweb-template-engine:

The basic alternative block of QWeb is t-if:

<t t-name="HomePageTemplate">


<t t-if="true == true"> true is true </t>

<t t-if="true == false"> true is not true </t>



Although QWeb does not contains any structure for else.

How to make a statement that comes down to "if (a true)"? It seems is not supported.

on 10/24/14, 8:05 AM

it removed my <> from a <> above. "ne" also does not work (and results in a server error)

on 10/24/14, 8:06 AM

try !=

Rove.design GmbH, Stefan Reisich
on 11/24/14, 7:19 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

3 follower(s)


Asked: 8/14/14, 12:21 PM
Seen: 39235 times
Last updated: 11/21/17, 5:41 AM