Smarty advanced features: how to use filters ,. The usage of smarty advanced features filters is analyzed in this article. For your reference, refer to the usage of the smarty advanced filter in advanced features,
This document describes how to use the smarty advanced filter. We will share this with you for your reference. The details are as follows:
Use of filters in Advanced features
1. pre-filter
Function remove_dw_comments ($ tpl_source, & $ smarty) {return preg_replace ("/
/U "," ", $ tpl_source); // remove comments from the original tpl file, make it not displayed in the compiled file} // register the pre-filter $ smarty-> register_prefilter ("remove_dw_comments"); $ smarty-> display ("test1.tpl ");
Test1.tpl
Use of filters
Annotation format
In this case, the comment is filtered out in the compiled file.
2. post filter
Function add_header_comment ($ tpl_source, & $ smarty) {return "<? Php echo \"
\ N \ "?> \ N ". $ tpl_source; // add header annotation} // after registration filter $ smarty-> register_postfilter ("add_header_comment"); $ smarty-> display ('test2. tpl ');
Template File:
Test2.tpl
Comments are generated in the header:
3. output filter
function protect_email($tpl_output, &$smarty){ $tpl_output = preg_replace('!(\S+)@([a-zA-Z0-9\.\-]+\.([a-zA-Z]{2,3}|[0-9]{1,3}))!', '$1%40$2', $tpl_output); return $tpl_output;}// register the outputfilter$smarty->register_outputfilter("protect_email"); $smarty->display("index.tpl");}$smarty->register_outputfilter("protect_email");$smarty->display("index.tpl");
I hope this article will help you design PHP programs based on the smarty template.
Articles you may be interested in:
- In smarty, use strip_tags to filter html tags and truncate to capture articles
- Solution to Smarty variable regulator failure
- FCKeditor smarty editor application PHP
- Summary of examples of common methods in smarty
- Thinkphp + smarty + uploadify
- Use the basic configuration of Smarty3 in CodeIgniter
The usage of the smarty advanced feature filter is analyzed in this article. I will share it with you for your reference as follows: Advanced features...