を経由して、テーブルの定義:私は小枝を使ってHTMLでテーブルを表示する必要がHTML:私は問題に直面しています列
が、私のオブジェクトscores
は(score.value
、score.name
)列ではなく、行を表します。もちろん、複数の行を使用して各行を表示することもできますが、その列を介してテーブルを作成することが可能かどうかを知りたがっていますか?またはこれを簡単に行うためのTwig機能があれば?
{% for score in scores %}
{% if loop.first %}<table class="table">{% endif %}
//HERE I got column
{% if loop.last %}</table>{% endif %}
{% endfor %}
レンダリングされたテーブルは、その後のように見えるはずです:
score1
、
score2
、
score3
だからHTMLで、それがどのように見えるはずです
score
scores
のループ
ある
|score1.name |score2.name |score3.name |etc...
|------------|------------|------------|--------
|score1.value|score2.value|score3.value|etc...
:
<table>
<tr>
<th>score1.name</th>
<td>score1.value</td>
</tr>
<tr>
<th>score2.name</th>
<td>score2.value</td>
</tr>
<tr>
<th>score3.name</th>
<td>score3.value</td>
</tr>
<tr>
<th>etc...</th>
<td>etc...</td>
</tr>
</table>
'score'も配列ですか? – GentlemanMax
@GentlemanMaxご関心をお寄せいただきありがとうございます。 'score'はオブジェクトで、' $ score-> getName() '、' $ score-> getValue() 'を使ってデータにアクセスできます。 – homer
ああ、データの列ですか? – GentlemanMax