This page of the documentation describes variables that can be used in a t-foreach loop in Qweb, but doesn't provide any examples of how to access those variables. I was thinking that I could use the $as_index variable to list line numbers on a sales order, but everything I have tried causes an error. Can anyone provide an example of how to output the index? Or, even better, the index + 1, since it starts at zero?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Boekhouding
- Voorraad
- PoS
- Project
- MRP
Deze vraag is gerapporteerd
try this code inside table,
<t t-set="i" t-value="1"/>
<tr t-foreach="o.order_line" t-as="l">
<td> <span t-esc="i"/> </td>
<t t-set="i" t-value="i+1"/>
</tr>
That's what I came up with, too. Just wanted to know how to do it in the manner described in the "documentation".
+1
I got the $as_index variable to work. Here is an example:
<tr t-foreach="o.order_line" t-as="l">
<td>
<span t-esc="l_index + 1" />
. . .
The index is zero-based, hence the addition of 1. Hope this helps.
This is pretty simple and straight forward.
When we define our loop like this:
<code>
<t t-foreach="people" t-as="person">
<tr>
<th scope="row"><span t-raw="person_index"/></th>
<td><span t-field="person.name"/></td>
<td><span t-field="person.age"/></td>
<td><span t-raw="person.weight"/></td>
</tr>
</t>
</code>
To get the current index/position of the person with the loop you can do person_index. i.e your variable_index or any other available variable withing the context of qweb loop.
I have tryed this:
<t t-set="i" t-value="1"/>
<tr t-foreach="o.order_line" t-as="l">
<td> <span t-esc="i"/> </td>
<t t-set="i" t-value="i+1"/>
</tr>
When the loop finishes, the ounter resets to 1. Does anyone kow a way to update a variable outside the loop? I would like to define a variable before the loop and set it to false. If I find what I am looking for inside the loop I would like to set the value of the variable to True. This var would later be used as a condition if a div is visible or not.
Any help is appreciated. Thx
var_index is automatically defined
Check https://www.odoo.com/documentation/8.0/reference/qweb.html#loops
Yes, that is the page I linked in my question. What I was hoping for was an example of usage. Everything I tried resulted in an error.
@Antony Lesuisse, Thanks for the link. I'm currently building a community module to add multiple product images for use in the website e-commerce pages here: https://github.com/OdooCommunityWidgets/website_multi_image unfortunately i've only just begun playing around with Odoo development and I have hit a brick wall trying to figure out how to create a t-foreach loop to output all images in the one2many in this module. Do you have any suggestions on how I could achieve this in 8.0?
https://www.odoo.com/documentation/8.0/reference/qweb.html Use the doc Luke ! :) On 12/04/2014 12:16 PM, Luke wrote: > @Antony Lesuisse, Thanks for the link. I'm currently building a community > module to add multiple product images for use in the website e-commerce pages > here: https://github.com/OdooCommunityWidgets/website_multi_image > unfortunately i've only just begun playing around with Odoo development and I > have hit a brick wall trying to figure out how to create a t-foreach loop to > output all images in the one2many in this module. Do you have any suggestions > on how I could achieve this in 8.0? > > -- > Luke > Sent by Odoo S.A. using Odoo > about Forum Post False
Geniet je van het gesprek? Blijf niet alleen lezen, doe ook mee!
Maak vandaag nog een account aan om te profiteren van exclusieve functies en deel uit te maken van onze geweldige community!
AanmeldenGerelateerde posts | Antwoorden | Weergaven | Activiteit | |
---|---|---|---|---|
|
0
dec. 15
|
4012 | ||
|
3
mrt. 15
|
17377 | ||
|
0
mrt. 15
|
3144 | ||
Set report orientation
Opgelost
|
|
1
mrt. 15
|
14063 | |
Inherit Qweb
Opgelost
|
|
4
feb. 24
|
47432 |
look into: https://learnopenerp.blogspot.com/2020/08/create-custom-report-in-odoo-using-qweb.html