跳至内容
菜单
此问题已终结
8 回复
124846 查看

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"/>
</t>

If you want to check for False condition:

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

形象
丢弃

I've been searching for how to check for a False condition for hours now, finally! Thanks!!

最佳答案

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

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

Cheers!! 


形象
丢弃
最佳答案

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

<div>

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

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

</div>

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

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

Thanks Stefan for the link

最佳答案

\https://www.youtube.com/watch?v=b2Z0PT0GTCI&list=UUZVWw0iLx0pFTzUzvl_XpcA&index=1

形象
丢弃
相关帖文 回复 查看 活动
5
8月 24
2704
1
8月 17
8867
1
7月 25
1701
1
5月 25
1688
1
4月 25
2270