,可以通过以下步骤实现:
$students = array(
array('name' => 'John', 'age' => 20, 'grade' => 'A'),
array('name' => 'Jane', 'age' => 19, 'grade' => 'B'),
array('name' => 'Mike', 'age' => 21, 'grade' => 'A-')
);
$loader = new \Twig\Loader\FilesystemLoader('/path/to/templates');
$twig = new \Twig\Environment($loader);
$template = $twig->load('table.twig');
<table>
<thead>
<tr>
<th>Name</th>
<th>Age</th>
<th>Grade</th>
</tr>
</thead>
<tbody>
{% for student in students %}
<tr>
<td>{{ student.name }}</td>
<td>{{ student.age }}</td>
<td>{{ student.grade }}</td>
</tr>
{% endfor %}
</tbody>
</table>
echo $template->render(array('students' => $students));
这样,TWIG模板将会根据你提供的数组数据生成一个包含学生信息的表格。
推荐的腾讯云相关产品:腾讯云云服务器(CVM)和腾讯云对象存储(COS)。
领取专属 10元无门槛券
手把手带您无忧上云