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

'pre'/'post'-Filter

'pre'-Filter und 'post'-Filter folgen demselben Konzept. Der einzige Unterschied ist der Zeitpunkt der Ausführung.

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

'pre'-Filter werden verwendet, um die Quellen eines Templates direkt vor der Kompilierung zu verarbeiten. Als erster Parameter wird die Template-Quelle, die möglicherweise bereits durch eine weiteren 'pre'-Filter bearbeitet wurden, übergeben. Das Plugin muss den resultierenden Wert zurückgeben. Achtung: Diese Werte werden nicht gespeichert und nur zum Kompilier-Zeitpunkt verwendet.

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

'post'-Filter werden auf die kompilierte Ausgabe direkt vor dem Speichern angewendet. Als erster Parameter wird der kompilierte Template-Code übergeben, der möglicherweise zuvor von anderen 'post'-Filtern bearbeitet wurde. Das Plugin muss den veränderten Template-Code zurückgeben.

Example 16.7. 'pre'-Filter Plugin


<?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. 'post'-Filter Plugin


<?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 2 plus 16? (Are you human?)

Sponsors [info]

Cheap Website Hosting @hostdone.com
Cheap Hosting @HostsVault
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