Prefilters
預過濾器
模板後過濾器是一些PHP函式,模板就是在那些函式編譯後才執行。這樣有利於預先處理你的模板,刪除不不需要的內容,監視對模板進行的操作,例如:預過濾器同樣能夠通過 load filter() 函式和設定 $autoload filters 變數來註冊或者從工具目錄裡載入。SMARTY將傳遞模板輸出作為第一個引數,通過自定義函式返回處理結果。
Example 15-2. using a template prefilter
<?php
// put this in your application
function remove_dw_comments($tpl_source, &$smarty)
{
return preg_replace("/<!--#.*-->/U","",$tpl_source);
}
// register the prefilter www.tw511.com
$smarty->register_prefilter("remove_dw_comments");
$smarty->display("index.tpl");
?>
{* Smarty template index.tpl *}
<!--# this line will get removed by the prefilter -->
|
|