0

How can a make a loop using chameleon and pyramid in my html? I search but i found nothing like that =/ Is easier use javascript in this case? I use datatable in MACADMIN(bootstrap theme).

<div class="table-responsive">
  <table cellpadding="0" cellspacing="0" border="0" id="data-table" width="100%">
    <thead>
      <tr>
        <th>
          Rendering engine
        </th>
        <th>
          Browser
        </th>
        <th>
          Platform(s)
        </th>
        <th>
          Engine version
        </th>
        <th>
          CSS grade
        </th>
      </tr>
    </thead>
    <tbody>
         Maybe put FOR here? like {for x items in "TABLE"}
      <tr>
        <td>
          {orgao_doc[x].nome}
        </td>
        <td>
          {orgao_doc[x].cargo}
        </td>
        <td>
          {orgao_doc[x].coleta}
        </td>
        <td>
          {orgao_doc[x].email}
        </td>
        <td>
          {orgao_doc[x].endereco}
        </td>
      </tr>
    </tbody>
  </table>
  <div class="clearfix">
  </div>
</div>
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Adley
  • 511
  • 1
  • 6
  • 19

1 Answers1

1

Use a tal:repeat attribute to repeat parts of a template, given a sequence:

<tbody>
  <tr tal:repeat="item orgao_doc">
    <td>${item.nome}</td>
    <td>${item.cargo}</td>
    <td>${item.coleta}</td>
    <td>${item.email}</td>
    <td>${item.endereco}</td>
  </tr>
</tbody>

The <tr> tag is repeatedly inserted into the output, once for each element in orgao_doc. The name item is bound to each element when rendering this part of the template.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • I saw "tal" in documentation from chameleon,i didn't understand. thanks, it's work fine, but i need to put $ before {item.nome} like ${item.nome} – Adley Sep 01 '14 at 14:50