php文件
<?php
$address = array('北京','天津','河北');
$birthday = array(year=>'1990',month=>'12',day=>array('1',"星期一"));
class Stu{
var $name;
var $sex;
var $age;
function study(){
echo "好好学习,天天向上!";
}
}
$stu1 = new Stu;
$stu1->name ="张三";
$stu1->age="12";
$stu1->sex="女";
include("libs/Smarty.class.php");
$smarty= new Smarty();
$smarty->template_dir="demo/templates";
$smarty->compile_dir="demo/templates_c";
$smarty->left_delimiter="<{";
$smarty->right_delimiter="}>";
$smarty->assign("name","周少杰");
$smarty->assign("arr",$address);
$smarty->assign("birthday",$birthday);
$smarty->assign("student",$stu1);
$smarty->display("test.tpl");
?>
tpl文件
hello!<br />
你好!<br />
我是<{$name}>!<br />
归属地:
<select>
<option><{$arr[0]}></option>
<option><{$arr[1]}></option>
<option><{$arr[2]}></option>
</select><br>
出生年月:
<{$birthday.year}>年<{$birthday.month}>月<{$birthday.day[0]}>日<{$birthday.day[1]}><br>
我是:<{$student->name}>,<{$student->age}>岁<br />
性别:<{$student->sex}><br />
我的宣言是:<{$student->study()}><br />