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

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.
Post a Comment
All comments are moderated. Support questions are ignored, use the forums instead.
Author:
Email: (not shown)
What is 16 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