Loops – t-foreach

A block of HTML can be repeated by iterating through a loop. We can use it to add the avatars of the task followers to the task's Kanban card.

Let's start by rendering just the partner IDs of the task, as follows:

<t t-foreach="record.message_partner_ids.raw_value" t-as="rec"> 
  <t t-esc="rec" />; 
</t> 

The t-foreach directive accepts a JavaScript expression evaluating to a collection to iterate. In most cases, this will be just the name of a to-many relation field. It is used with a t-as directive to set the name to be used to refer to each item in the iteration.

The t-esc directive used next evaluates the provided expression, just the rec variable name in this case, and renders it as safely escaped HTML.

In the previous ...

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.