您的位置:首页 > 其它

11.smarty 对象

2016-03-06 17:12 344 查看
对象:





过滤器:









后预处理器:





输出滤镜:



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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: