php smarty整理(二)自定义Smarty模板
2017-08-27 16:05
453 查看
<?php
/*
*@简单的Smarty的自定义模板
*/
class MyTpl(){
//模板中的变量
protected $tpl_vals=array();
/*
*@显示模板
*/
public function display($tpl){
$contents=file_get_contents($tpl);
foreach ($this->tpl_vals as $key => $val) {
$contents = str_replace("{\$".$key."}", $val, $contents);
}
$complieFile='complie/'.md5($tpl).'.php';
file_put_contents($complieFile, $contents);
require_once $complieFile;
}
/*
*@显示数据
*/
public function assign($name,$value){
$this->tpl_vals[$name]=$value;
}
}
$tpl= new MyTpl();
$tpl->assign('test','this is a test');
$tpl->display('xxx.html');
/*
*@简单的Smarty的自定义模板
*/
class MyTpl(){
//模板中的变量
protected $tpl_vals=array();
/*
*@显示模板
*/
public function display($tpl){
$contents=file_get_contents($tpl);
foreach ($this->tpl_vals as $key => $val) {
$contents = str_replace("{\$".$key."}", $val, $contents);
}
$complieFile='complie/'.md5($tpl).'.php';
file_put_contents($complieFile, $contents);
require_once $complieFile;
}
/*
*@显示数据
*/
public function assign($name,$value){
$this->tpl_vals[$name]=$value;
}
}
$tpl= new MyTpl();
$tpl->assign('test','this is a test');
$tpl->display('xxx.html');
相关文章推荐
- php之smarty模板自定义标签
- 写 smarty 插件 前奏 动态 注册 自定义 php 函数 模板中使用
- PHP Smarty 模板 自定义插件
- 对比JAVA学习PHP系列:高级:PHP的模板引擎Smarty
- PHP Yii框架中使用smarty模板
- 自定义微信图文模板注意事项整理
- 如何在smarty模板中执行php代码
- PHP项目开发中最常用的自定义函数整理
- 如何在smarty模板中使用自定义函数
- 【PHP高级】smarty模板
- PHP中轻型模板处理类:Smarty-Light
- 陈力:传智播客古代 珍宝币 泡泡龙游戏开发第51讲:PHP中smarty模板技术介绍
- php之Smarty模板使用方法示例详解
- PHP模板之Smarty安装与使用入门教程
- Yaf 结合用户自定义的视图(模板)引擎Smarty(Yaf + Smarty)
- [PHP]Smarty模板造成的自动加载函数__autoload失灵问题
- html+js+PHP(使用了smarty模板技术)+mysql实现二级动态下拉列表(select)
- 微信推送模板消息的PHP代码整理
- php用Smarty模板生成html文件
- smarty php 模板开发