为了以后更方便的使用smarty,我们可以将“加载smarty 模版引擎”、“建立 smarty 对象”、“设定smarty 对象的参数”这三步放到一个公共的php文件内,以后在需要使用的地方我们直接reuqire一下,即可,例如:
1. 建立一个main.php
template_dir = root.templates.dir_sep;
$tpl->complie_dir = root.templates_c.dir_sep;
$tpl->config_dir = root.configs.dir_sep;
$tpl->cache_dir = root.cache.dir_sep;
$tpl->left_delimiter = $tpl->right_delimiter = }>;
?>
注1:此处为何要使用directory_separator?(点击查看)
注2:left_delimiter和right_delimiter为左右结束符变量,此处可定义为其他字符串(默认为{})。
2. 在templates下,新建立一个test.htm
3. 调用模板页给title和content填充内容,新建一个test_smarty_1.php
assign(title, new message);
$tpl->assign(content, this is test smarty!);
$tpl->display(test.htm);
?>
也可以这样写
assign(array(title=>newmessage, content=>this is test smarty!));
$tpl->display(test.htm);
?>
输出结果:
页面title显示:newmessage
页面内容显示:this is test smarty!
http://www.bkjia.com/phpjc/478801.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/478801.htmltecharticle为了以后更方便的使用smarty,我们可以将“加载smarty 模版引擎”、“建立 smarty 对象”、“设定smarty 对象的参数”这三步放到一个公共的...