Get Smarty

Smarty Icon

You may use the Smarty logo according to the trademark notice.

Smarty Template Engine Smarty Template Engine

For sponsorship, advertising, news or other inquiries, contact us at:

Check reviews of PHP Web Hosting, compatible with Smarty Templates

Prefiltros/Posfiltros

Plugins Prefilter e postfilter são muito similares em conceito; onde eles diferem é na execução -- mais precisamente no tempo de suas execuções.

string smarty_prefilter_name( $source,  
  &$smarty);  
string $source;
object &$smarty;
 

Prefilters são usados para processar o fonte do template imediatamente antes da compilação. O primeiro parâmetro da função de prefilter é o fonte do template, possivelmente modificado por alguns outros prefilters. O Plugin é suposto retornar o fonte modificado. Note que este fonte não é salvo em lugar nenhum, ele só é usado para a compilação.

string smarty_postfilter_name( $compiled,  
  &$smarty);  
string $compiled;
object &$smarty;
 

Postfilters são usados para processar a saída compilada do template (o código PHP) imediatamente após a compilação ser feita e antes do template compilado ser salvo no sistema de arquivo. O primeiro parâmetro para a função postfilter é o código do template compilado, possivelmente modificado por outros postfilters. O plugin é suposto retornar a versão modificada deste código.

Example 16.7. Plugin prefilter

<?php
/*
 * Smarty plugin
 * -------------------------------------------------------------
 * File:     prefilter.pre01.php
 * Type:     prefilter
 * Name:     pre01
 * Purpose:  Convert html tags to be lowercase.
 * -------------------------------------------------------------
 */
 function smarty_prefilter_pre01($source, &$smarty)
 {
     return preg_replace('!<(\w+)[^>]+>!e', 'strtolower("$1")', $source);
 }
?>

Example 16.8. Plugin postfilter

<?php
/*
 * Smarty plugin
 * -------------------------------------------------------------
 * File:     postfilter.post01.php
 * Type:     postfilter
 * Name:     post01
 * Purpose:  Output code that lists all current template vars.
 * -------------------------------------------------------------
 */
 function smarty_postfilter_post01($compiled, &$smarty)
 {
     $compiled = "<pre>\n<?php print_r(\$this->get_template_vars()); ?>\n</pre>" . $compiled;
     return $compiled;
 }
?>

Comments
No comments for this page.
Post a Comment
All comments are moderated. Support questions are ignored, use the forums instead.
Author:
Email: (not shown)
What is 19 plus 15? (Are you human?)

Sponsors [info]

Cheap Website Hosting @hostdone.com
email marketing @ActiveCampaign
broadband deals @BroadbandGenie
Best UK Web Hosting @webhost.uk.net
Reliable UK and US Web Hosting @rshosting.com
Cheap US and UK Web Hosting @infrenion.com
I.T Certification Exams @pass-guaranteed.com
Certification Practice Tests @firsttrycertify.com
Certification Practice Exam Questions @ace-it-certifications.com
Broadband Speed Test @broadbandspeed.co.uk
bulk email software @americaint.com
ASP.NET hosting @aspnethosting.co.uk