[英]Print an array in Twig
我有一個帶有此列的表:
login ,couleur1,parties,gagnees
我想打印一個像這樣的數組:
在Silex中,我將所有數據存儲在一個數組中
$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]?>
在Twig中,我嘗試將它們對齊,但無法像照片中那樣。
{% 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 %}
我不會分離CSS和Twig就可以做到這一點。
將會是這樣的:
<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>
並為顏色和外觀應用一些CSS。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.