oTree Forum >

Extracting the first three elements of a list using the slicing operator is not working.

#1 by RA_203

I have list of 6 prices where first three correspond to good A and the other 3 to good B; and I am trying to put the first3 into the first row using the code below and then I want the last three into the second row. I have the prices in 1 list because I want the player to only be able to make one choice in the table. But, when trying the following {{for field in form[:3]}} for example, I get an error. What other steps can I do to fix this? 

<table>
      <tr>
    <th>Good</th>
    <th>Brand 1</th>
    <th>Brand 2</th>
     <th>Brand 3</th>
      </tr>
      <tr>
    <td> A </td>
      {{ for field in form }}
            {{ for choice in field }}
        <td> {{ choice }}  {{ choice.label }}</td>
              {{ endfor }}
      {{ endfor }}
       </tr>
      <tr>
    <td>B </td>
      {{  for field in form }}
            {{for choice in field }}
        <td> {{ choice }}  {{ choice.label }}</td>
              {{ endfor }}
      {{ endfor }}
      </tr>
</table>

Write a reply

Set forum username