Get Smarty

Donate

Paypal

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:

Sites Using Smarty

Advertisement

Prefiltri/Postfiltri

I plugin prefiltro e postfiltro sono molto simili concettualmente; la differenza sta nel momento della loro esecuzione.

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

I prefiltri si usano per processare il codice sorgente del template immediatamente prima della compilazione. Il primo parametro passato alla funzione prefiltro è il sorgente del template, eventualmente modificato da qualche altro prefiltro. Ci si aspetta che il plugin restituisca il sorgente modificato. Notate che questo sorgente non viene salvato da nessuna parte, è usato solo per la compilazione.

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

I postfiltri si usanno per processare l'output compilato del template (il codice PHP) immediatamente dopo la compilazione stessa, ma prima che il template compilato venga salvato sul filesystem. Il primo parametro passato alla funzione postfiltro è il codice compilato, eventualmente modificato da altri postfiltri. Ci si aspetta che il plugin restituisca la versione modificata di questo codice.

Example 16.7. plugin prefiltro


<?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 postfilro


<?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.

Advertisement

Sponsors [info]

Sponsors