Smarty預篩檢程式

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.xuhuhu.com
$smarty->register_prefilter("remove_dw_comments");
$smarty->display("index.tpl");
?>

{* Smarty template index.tpl *}
<!--# this line will get removed by the prefilter -->


上一篇: Smarty對象 下一篇: Smarty輸出濾鏡