简体   繁体   中英

Print an array in Twig

I Have a table with this columns:

login ,couleur1,parties,gagnees

I would like to print an array exactly like this one:

在此处输入图片说明

In Silex I get all data in an array

$app->get('/userlist', function(Application $app) {

$recup= $app['db']->executeQuery('SELECT * FROM users');
$results = $recup->fetchAll();

return $app['twig']->render('example.twig', array('users' => $results));
});

$app->run();
[enter image description here][2]?>

In Twig I tried to align them, but I can't get it like in the photo.

 {% for row in users %}
    <ul style="list-style: none;">
        <li style="float:left; margin-right:30px" >{{ row.login }}</li>
        <li style="float:left; margin-right:30px">{{row.parties}}</li>
        <li style="float:left; margin-right:30px">{{row.couleur1}}</li>
        <li style="float:both">{{row.couleur2}}</li>
    </ul>
{% endfor %}

I would make that without separating CSS and Twig.

It will be something like this:

<table>
  <tr>
    <td>Joueur</td>
    <td>Parties</td>
    <td>Gagness</td>
    <td>Colueur Preferee</td>
  </tr>
  {% for row in users %}
    <tr>
        <td>{{ row.login }}</td>
        <td>{{row.parties}}</td>
        <td>{{row.couleur1}}</td>
        <td>{{row.couleur2}}</td>
    </tr>
  {% endfor %}

</table>

and apply some CSS for colors and looks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM