Smarty:是一个使用PHP写出来的模板引擎,是目前业界最著名的PHP模板引擎之一。它分离了逻辑代码和外在的内容,提供了一种易于管理和使用的方法,用来将原本与HTML代码混杂在一起PHP代码逻辑分离
-------------------------------------------------------------------------------
使用:
下载smarty压缩文件:解压之后libs文件夹是 有用的其他的文件夹可以忽略
把libs文件放在你的服务器上,根目录下即可
这个文件夹下中 有一个文件是smarty.class.php文件中已经写明一些使用设置
在libs的同级目录下新建cache configs php templates templates_c 说明:php用来放置php文件 templates用来放置html模板文件
都是可以个更改的
然后直接测试一下
php中的index.php文件
<?php require '../libs/Smarty.class.php'; $smarty = new Smarty(); $smarty->assign('age',27); $arr = array("张一山",'19','boy'); $smarty->assign("peo",$arr); $smarty->display('../templates/index.html');
templates目录下的index,html文件
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> </head> <body> 年龄{$age} {foreach $ as $k=>$v} {$k}=>{$v}<br/> {/foreach} </body> </html>
//在浏览器中输入对应的php中的index.php 文件即可
