Aide

0

How to add Class to only the first element in t-foreach odoo 12

I want to add class only when $_first evaluated to true

Example:   

 <div t-attf-class="carousel-item {{ $_first }}">

To be:

Incase True:  <div t-attf-class="carousel-item active">

Incase of false: <div t-attf-class="carousel-item">

2 Comments
Avatar
Discard

Thanks Parth, It's works.

Could you Please explain what the meaning of (and 'active' or ' ') and how odoo evaluate it

1 Réponse
2
Avatar
Parth Gajjar
Best Answer

Try this one

<t t-foreach="records" t-as="rec">
    <div t-attf-class="carousel-item #{ rec_first and 'active' or '' }">
    </div>
</t>
it is not $_first you should replace $ with the value of t-as


Avatar
Discard