Smarty 和阵列
我想将此数组作为表格加载到 Smarty 中。
数组:
Array
(
[0] => Array
(
[name] => VS1
[price] => 350
[ram] => 256
[cpu] => 2267
[hdd] => 5
[traff] => 0
[os] => Linux
[country] => Russia
)
[1] => Array
(
[name] => VS2
[price] => 465
[ram] => 512
[cpu] => 2267
[hdd] => 5
[traff] => 0
[os] => Linux
[country] => Russia
)
)
在源代码中,我想要这个
<tr>
<td>VS1</td>
<td>350</td>
<td>256</td>
<td>2267</td>
<td>5</td>
<td>0</td>
<td>Linux</td>
<td>Russia</td>
</tr>
<tr>
<td>VS2</td>
<td>465</td>
<td>512</td>
<td>2267</td>
<td>5</td>
<td>0</td>
<td>Linux</td>
<td>Russia</td>
</tr>
这可能吗?我正在尝试 foreach 循环,但没有结果。 您能给我一个有效的 Smarty 代码吗?
I want to load this array as table in Smarty.
Array:
Array
(
[0] => Array
(
[name] => VS1
[price] => 350
[ram] => 256
[cpu] => 2267
[hdd] => 5
[traff] => 0
[os] => Linux
[country] => Russia
)
[1] => Array
(
[name] => VS2
[price] => 465
[ram] => 512
[cpu] => 2267
[hdd] => 5
[traff] => 0
[os] => Linux
[country] => Russia
)
)
In source, i want this
<tr>
<td>VS1</td>
<td>350</td>
<td>256</td>
<td>2267</td>
<td>5</td>
<td>0</td>
<td>Linux</td>
<td>Russia</td>
</tr>
<tr>
<td>VS2</td>
<td>465</td>
<td>512</td>
<td>2267</td>
<td>5</td>
<td>0</td>
<td>Linux</td>
<td>Russia</td>
</tr>
Is this possible? I am trying foreach cycles, but its no result.
Can you give me a working Smarty code please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
foreach 总是为我工作。假设,
$smarty
是您已经初始化且正在运行的 smarty 3 实例,$arr
是您的数组。您需要在 php 中将数组分配给 smarty:
然后在模板中使用 foreach 循环遍历它:
foreach always worked for me. lets asume,
$smarty
is your already initialized and working smarty 3 instance, and$arr
is your array.you need to assign the array to smarty in php:
then you loop through it with foreach in the template:
这应该可以解决问题;)
This should do the trick ;)
注意另一种书写方式...检查您的 Smarty 版本是否正确。
Mind the other way of writing... check your Smarty version for the correct one.