int_tow
int_tow

Reputation: 73

How add a style in qweb only if a qweb var is true, without duplicate the code?

I want output 20 td with a css style depends on a qweb var. Is where any alternative to duplicate the whole code like this:

<table>
...
<td>
<t t-if="line_odd">
  <td class="padding-top"><p t-esc="line.field1">...</td>
...
  <td class="padding-top"><p t-esc="line.field20" />...</td>
</td>

<t t-if="not line_odd">
  <p class="no-padding-top"><p t-esc="line.field1">...</td>
...
  <p class="no-padding-top"><p t-esc="line.field20">...</td>
</td>

because this code isn't valid a)

<tr>
  <t t-if="line_odd">
     <td class="padding-top">
  </t>
  <t t-if="not line_odd">
     <td class="padding-top">
  </t>
     <p>...</p>
  </td>
</td>

b)

<td <t t-if="true">class='padding-top'</t> >
   <p>...</p>
</td>

Upvotes: 1

Views: 395

Answers (1)

simahawk
simahawk

Reputation: 2431

use t-att-class or t-attf-class if you need to combine default strings:

<td t-att-class="line_odd and 'no-padding' or 'padding-top'">

<td t-attf-class="foo #{line_odd and 'no-padding' or 'padding-top'}">

See docs.

Upvotes: 1

Related Questions