{
if ($tpl_var!=null) {
$this->tpl_vars[$tpl_var]=$val;
}
}
function display($tpl_file) //编译显示
{
$tpl_file_path=$this->template_dir.$tpl_file; //模板文件
$complie_file_path=$this->complie_dir."com_".$tpl_file.".php"; //编译文件
if (!file_exists($tpl_file_path)) {
return false;
}
//编译文件不存在则编译,模板修改过则重新编译
if (!file_exists($complie_file_path)||filemtime($complie_file_path)tpl_vars["\1"];?>'
);
$newstring=preg_replace($pattren,$replace,$tpl_file_con);
file_put_contents($complie_file_path,$newstring);
}
include($complie_file_path); //显示编译文件
}
}
传值页面
assign("title","hello");
$mysmarty->assign("say","hello");
$mysmarty->display("intro.html");
模板页面
{%title}
{%title}
{%say}