如何在smarty模板文件中分配数组? [英] How to assign an array within a smarty template file?
本文介绍了如何在smarty模板文件中分配数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否可以在Smarty模板文件中将数组分配给变量?我已经尝试过了
I was wondering if it was possible to assign an array to a variable within a Smarty template file? I have tried this
{assign var='file' value = array('dir','doc','exe')}
但是当我打印出数组时,它会产生以下结果:
But when I print out the array it produces this:
array(\'dir\',\'doc\',\'exe\')
如何停止Smarty对数组值进行转义?
How can I stop Smarty escaping the array values?
预先感谢
推荐答案
{php}
$this->assign("array", array('dir','doc','exe'));
{/php}
{foreach from=$array item=item}
{$item}
{/foreach}
Smarty v.3 中提供了新语法
{$array = ['item1','item2',$item3]}
有关更多详细信息,请参见: http://www.smarty.net /docs/en/language.syntax.variables.tpl
see for more details : http://www.smarty.net/docs/en/language.syntax.variables.tpl
这篇关于如何在smarty模板文件中分配数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文