11.smarty 对象
2016-03-06 17:12
344 查看
对象:
过滤器:
后预处理器:
输出滤镜:
MyFilter.php
test6.tpl
过滤器:
后预处理器:
输出滤镜:
MyFilter.php
<?php require_once './libs/Smarty.class.php'; $smarty = new Smarty(); //$smarty->debugging = true; $smarty->left_delimiter = "{<"; $smarty->right_delimiter = ">}"; //这是一个函数 function remove_dw_contents($tpl_source,&$smarty) { //echo "OKOK";die; //这里的预处理器就是把 tpl 文件中的<!--#.*--> 替换成 "" return preg_replace("/<!--#.*-->/U","aaa",$tpl_source); } //这个是注册一个预处理器,相当于把函数查到 $smarty->display() 函数 之前 //没有下面一句话,会生成注释 //切面编程,拦截器 $smarty->register_prefilter('remove_dw_contents'); //后预处理器 function add_header_comment($tpl_source, &$smarty) { return "<?php echo \"<!-- W J H -->\n\" ?>\n".$tpl_source; } $smarty->register_postfilter('add_header_comment'); $smarty->display('test6.tpl');
test6.tpl
<h1>test6页面</h1> <!--#hello world--> <h2>其他内容</h2>
相关文章推荐
- centos 下tomcat 自动启动
- 预习心得
- java集合框架
- java 线程池 Executors 及 ThreadPoolExecutor
- Python中NumPy基础使用
- Android SO逆向1-ARM介绍
- windows下的C:\Windows\System32\drivers\etc\hosts
- JS事件处理和事件对象
- vs2015 mvc项目数据迁移报错
- Linux基础--用户与组
- myeclipse加载项目,出现"大量红叉"
- Android菜鸟认知——Intent和Intent filter初印象
- 黑客游戏
- 《疯狂Java讲义》——闭包和回调
- MATLAB计算昨天的日期
- 运行React-Native项目
- 运行React-Native项目
- vim自动补全代码(代码提示)以及我的vim配置文件 .
- Android 官方推荐 : DialogFragment 创建对话框
- Solr学习笔记-在Tomcat上部署执行Solr