SMARTY_Assistant怎么用

来源:百度知道 编辑:UC知道 时间:2024/06/28 10:45:24
我在学习smarty,谢谢大家帮忙

index.php:

//初始化类
$smarty = new Smarty;

//将数组变量付给 smarty下边的变量 contacts
$smarty->assign('Contacts',
array('fax' => '555-222-9876',
'email' => 'zaphod@slartibartfast.com',
'phone' => array('home' => '555-444-3333',
'cell' => '555-111-1234')));

// 指定模板文件
$smarty->display('index.tpl');

index.tpl:
//输出对应的数组元素值
{$Contacts.fax}<br>
{$Contacts.email}<br>
{* you can print arrays of arrays as well *}
{$Contacts.phone.home}<br>
{$Contacts.phone.cell}<br>

OUTPUT:

555-222-9876<br>
zaphod@slartibartfast.com<br>
555-444-3333<br>
555-111-1234<br>

好好学
http://linux.chinaitlab.com/PHP/38324.html