How can I make a "for-loop" with a specific number of loops in Qweb?

ChesuCR picture ChesuCR · Jul 17, 2015 · Viewed 13.3k times · Source

I would like to make a loop to print elements an exact amount of times. Something like this:

<t t-for="o.label_qty" >
...
</t>

Where o.label_qty is an integer number.

But I can use only a t-foreach loop in qweb:

<t t-foreach="o.pack_operation_ids" t-as="l" >
...
</t>

Is there a way to do this?

If not I'm thinking the only solution is to create a dummy list with o.label_qty elements and write it in the foreach.

Answer

Daniel Reis picture Daniel Reis · Jul 18, 2015

The t-foreach directive accepts a Python expression. So, you could use range() just like in Python for loops:

<t t-foreach="range(o.label_qty)" t-as="l">
...
</t>