smarty---参数传递和参数取值

参数传递和参数取值示例

<?php
//引进smarty的类文件
require_once "../include/setup.php";//引入类文件

$smarty = new Smarty_MyBlog();//创建对象
$smartyObj = $smarty->setUpSmarty();//配置smarty目录

$smarty->assign('name','zhangdapeng');//传递参数
$smarty->assign('firstname','Doug');
$smarty->assign('lastname','Devid');
$smarty->assign('meetingplace','New York');

$smarty->assign('Contacts',
        array('fax'=>'555-333-999',
              'email'=>'[email protected]',
              'phone'=>array('home'=>'123456',
                             'cell'=>'987654321')
            ));

$smarty->assign('Contacts1',
               array('555-333-999',
                     '[email protected]',
                     array('123456','987654321')
            ));
$smarty->display('index.html');//要显示的文件
?>

{* Smarty注释 *}
Hello {$name}, Welcome to Smarty!
Your Name is {$firstname} {$lastname};<br />

Your Contacts : 
{$Contacts['fax']}
{$Contacts['email']}
{$Contacts['phone']['home']}
{$Contacts['phone']['cell']}
<br />
Your Contacts2:
{$Contacts1[0]}
{$Contacts1[1]}
{$Contacts1[2][0]}
{$Contacts1[2][1]}

你可能感兴趣的:(smarty---参数传递和参数取值)