Conditionals – t-if

Our Kanban view used the t-if directive in the card option menu to make some options available depending on some conditions. The t-if directive expects an expression to be evaluated in JavaScript when rendering Kanban views on the client side. The tag and its content will be rendered only if the condition evaluates to true.

As an example, to display the task effort estimate in the Kanban card only if it has a value, add the following after the date_deadline field:

<t t-if="record.effort_estimate.raw_value gt 0"> 
  <li>Estimate <field name="effort_estimate"/></li> 
</t> 

We used a <t t-if="..."> element so that if the condition is false, the element produces no output. If it is true, only the contained <li> element is rendered ...

Get Odoo 11 Development Essentials - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.