smarty模板的第一个dem... 登录

smarty模板的第一个demo的简单应用

1,下好的压缩包解压之后是这样的:

微信图片_20180312131304.png

目录中,demo文件夹为示例文件。Libs为程序文件。
/libs/Smarty.class.php   #主文件
/libs/sysplugins/  #内部plugin
/libs /plugins/   #外部plugin,可自由扩充

我们只需要用到libs包,把libs包放到自己项目的根目录

打开Smarty.class.php文件:

查看构造函数

微信图片_20180312131827.png

/cahce/   #放置缓存文件
/configs /   #放置可以载入的配置文件
/templates/   #放置模板文件
/templates_c/    #放置对模板编译后的文件


2,在libs根目录下新建这四个文件夹

微信图片_20180312132326.png

3,在template模板文件里新建test.html文件

代码如下:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>test</title>
</head>
<body>
我们网站的网址是:{$add}
</body>
</html>

4,根目录下新建test.php文件

代码如下:

<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/3/12 0012
 * Time: 下午 12:56
 */
require './libs/Smarty.class.php';
$smarty=new Smarty();
$add='www.php.cn';
$smarty->assign( 'add' , $add );
$smarty->display('./templates/test.html');

5,运行index.php

展示如下:

微信图片_20180312132720.png

下一节
<?php echo "smarty的简单应用";
提交 重置代码
章节 评论 笔记 课件
  • 取消 回复 发送
  • 取消 发布笔记 发送