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

Filtri di output

Quando il template viene richiamato via display() o fetch(), è possibile eseguire uno o più filtri sul suo output. Ciò è diverso dai postfiltri, perché questi ultimi lavorano sul template compilato prima che venga salvato su disco, mentre i filtri dioutput lavorano sull'output del template quando viene eseguito.

I filtri di output possono essere registrati o caricati dalla directory plugins con la funzione load_filter() oppure impostando la variabile $autoload_filters. Smarty passerà l'output del template come primo argomento, e si aspetterà che la funzione restituisca il risultato dell'esecuzione.

Example 15.4. uso di un filtro di output


<?php
// mettiamo questo nell'applicazione
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;
}

// registriamo il filtro
$smarty->register_outputfilter("protect_email");
$smarty->display("index.tpl");

// ora ogni indirizzo email nell'output del template avrà una semplice
// protezione contro gli spambot
?>

    

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 2 plus 5? (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