我的位置: 首页 >> 网 站 >> 建站知识

模板引擎Smarty介绍

一、mvc需要模板
模板",逻辑和表示依靠它联系。它是结合了html和脚本语言特征的一种表达方式。通过这种方式,表示层可以按照用户所希望的格式来显示经过逻辑层处理过的数据。如果你有windows平台下mfc的开发经验,那么一定会很熟悉document/documenttemplate/view的封装,这就是一个很典型的mvc例子。对于web应用来说,个人认为j2ee中的ejb/servlets/jsp是最强大的,当然还有简洁优美的structs。另一个很有名的实现就是com/dcom+asp,这个组合在我国是最多人使用的。
<html>
<head>
<title>$greetings</title>
</head>
<body>
$greetings
<body>
</html>
二、为什么选smarty?
三、可能遇到的问题
$smart->template_dir="smarty/templates/"
$smart->compile_dir="smarty/templates_c/"
$smart->config_dir="smarty/configs/"
$smart->cache_dir="smarty/cache/"
$smart->left_delimiter="{/"
$smart->right_delimiter="/}"
四、反衬和类比
$tpl->set_file('phplib','bigfile.htm')
$tpl->set_block('phplib','row','rows')
for($j=0$j<10$j++){
$tpl->set_var('tag',"$j")
$tpl->parse('rows','row',true)
}
$tpl->parse('out','phplib')
$tpl->p('out')
$smart->assign('row',$row)
$smart->display('bigfile.htm')


五、结论

客户中心

版权2005-2020    聚卓网络有限公司    电话:18589057325    QQ:2338754269   粤ICP备14021702号

地址:深圳市宝安区 37区龙井一路100号 新乐社区工作站办公大楼侧门6楼(近翻身路、新乐社区健康服务中心)

技术支持: 网站建设