Set values on variables – t-set

For more complex logic, we can store the result of an expression into a variable to use it later in the template. This is to be done using the t-set directive, naming the variable to set followed by the t-value directive with the expression calculating the value to assign.

As an example, the following code renders missed deadlines in red, just as in the previous section, but uses a red_or_black variable for the CSS class to use, as shown in the following:

<t t-set="red_or_black"   t-value="     record.date_deadline.raw_value and 
     record.date_deadline.raw_value lte (new Date()) 
     ? 'oe_kanban_text_red' : ''" /> 
<li t-att-class="red_or_black"> 
  <field name="date_deadline" /> 
</li> 

Variables can also be assigned HTML content, ...

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.