博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
如何配置Smarty模板
阅读量:4653 次
发布时间:2019-06-09

本文共 1020 字,大约阅读时间需要 3 分钟。

<?php

//首先包含Smarty类文件

include_once('Smarty/Smarty.class.php');

//实例化Smarty类文件

$smarty=new Smarty();

//设置配置目录,可以不设置

//注意一下文件夹需要自己创建,并且可以改名

//$smarty->config_dir=

//$smarty->cache_dir="./caches";//设置缓存目录

//$smarty->caching=true;//关闭缓存,调试中建议关闭默认为关闭即设置成false

$smarty->cache_lifetime=60;//单位为秒     设置缓存时间

$smarty->template_dir="./templates";//设置模版目录

$smarty->compile_dir="./templates_c";//设置编译目录必选

$smarty->cache_dir="./smarty_cache";//缓存文件夹可选为减轻压力

//设置开始结束边界默认为{} 但容易与javascript冲突

$smarty->left_delimiter="{";

$smarty->right_delimiter="}";

?>

4.演示一下Smarty模板的使用  

新建一个php文件 文件名为helloworld.php  代码如下

<?php

//包含smarty配置文件

include 'smarty.inc.php';

//将变量name赋值为helloworld

$smarty->assign('name','Hello world!');

//在模板下的helloworld.html文件显示注意这里必须对应的是模板目录下的helloworld.html换成别的文件名不行,必须和php的文件对应

$smarty->display('helloworld.html');

?>

设置helloworld.html文件

<html>

{$name}<!--输出到浏览器页面-->

</html>

注意:两个文件名必须相同除扩展名!还要将smarty.inc.php 和helloworld.php放于同一目录下

5.下来就可以参考Smarty手册和demo尝试了,一起加油phper!

转载于:https://www.cnblogs.com/achengmu/p/3866291.html

你可能感兴趣的文章
【机器学习】贝叶斯公式
查看>>
445端口打开方法
查看>>
生成器
查看>>
Pycharm 创建 Django admin 用户名和密码
查看>>
python2.6升级2.7导致yum无法使用 No module named yum
查看>>
maintenance.go
查看>>
【转载】NativeSQL实例
查看>>
LeetCode--434--字符串中的单词数
查看>>
并发容器之CopyOnWriteArrayList(转载)
查看>>
Spark技术栈
查看>>
日志及参数的乱码问题
查看>>
Python开发简单爬虫
查看>>
克服"水土不服",融云助攻小象直播杀破"出海重围"
查看>>
spring Boot 入门--为什么用spring boot
查看>>
负载均衡
查看>>
tar and war的一些命令
查看>>
BZOJ 1260&UVa 4394 区间DP
查看>>
CentOS或Redhat上装memcached (包括64位系统)
查看>>
C 字符串数组排序
查看>>
ios开发学习--列表(Table)效果源码分享--系列教程4
查看>>