Smarty就是为了分层,提高开发效率。实际原理还是把东西混在一起编译显示。学了jsp的看这个很简单。 index.php: $smarty=new Smarty; //这里不是 $title ,就类似于jsp中的setAttribute,然后页面用el表达式取出 $smarty ->assign('title','第一个smarty程序')); $smarty ->assign('content','hello world‘); $smarty ->display(index.tpl); index.tpl: {$title} {$content} 运行index.php就显示标题和内容了。 tpl文件中的变量主要来自3个部分: 1.来自php页面的变量也就是assign方法传过来的变量,直接使用。 2.保留变量。 3.从配置文件读取数据。 A.#配置文件.conf文件中的变量# B.$smarty.config.变量名
tpl文件里注释用* * :{*要注释的内容*} 取数组内容方式除了[]也可以用. 例如:$arr[type] 也可以用$arr.type 使用get获取url中的参数:$smarty.get.id 变量修饰的一般格式: {variable_name|modifier_name1|modifier_name2:pram1:pram2...} tpl文件中的流程控制语句格式:{xx } 显示文本 {/xx} section循环{section name="sec_name" loop=$arr_name start=num step=num}//像jstl中的foreach循环 smarty程序设计: 1.和smarty模版之间的交互,如assign。display等 2.配置smarty。如变量$template_dir,$config_dir等 |
初学Smarty
最新推荐文章于 2024-08-08 14:19:42 发布
2009-10-07 16:13