Re: [SMARTY] [Beginner] How to use prefilters ?

From: Date: Fri, 17 Oct 2003 16:50:50 +0000
Subject: Re: [SMARTY] [Beginner] How to use prefilters ?
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-10378@lists.php.net to get a copy of this message
if you do: $this->register_prefilter('smarty_prefilter_literalScriptAndStyle'); you have to include the file implemennting the filter yourself. (you just pass a function-name to be registered) if you want it to be autoloaded, you have to do: $smarty->load_filter('pre', 'literalScriptAndStyle'); (this checks your plugins-path and requires prefilter.literalScriptAndStyle.php accordingly) i'm sure it's documented this way, but didn't bother double-checking. greetings messju On Fri, Oct 17, 2003 at 12:40:57PM -0400, Mark Priatel wrote: > Try doing a simple test, making sure that your prefilter function is in the > same file (scope) of the script that you're calling smarty from, and follow > the exaple at: > > > http://smarty.php.net/manual/en/advanced.features.prefilters.php > > It really should be as simple as: > > 1) declaring a prefilter function > 2) registering it within smarty > 3) calling display/fetch > > It sounds like the error might have something to do with function not being > 'included' within your application. > > -mark > > --------------------------- > Mark Priatel > Iolog Web Communications > http://www.iolog.com > > > > -----Original Message----- > From: Luc Saint-Elie [mailto:luc@saint-elie.com] > Sent: Friday, October 17, 2003 12:14 PM > To: Smarty General > Subject: Re: [SMARTY] [Beginner] How to use prefilters ? > > Monte, > > I'm sorry to upset with this stupid problem but I still fail : > > > Fatal error: Smarty error: [plugin] prefilter 'literalScriptAndStyle' is > not implemented in f:\easyphp\www\PATH_TO\Smarty.class.php on line 1895 > > Is there somewhere a complete example or a tutorial on prefilter use ? > > Luc > > > At 17:10 17/10/2003, Monte Ohrt wrote: > >Use this to register the prefilter: > > > >$smarty->register_prefilter('literalScriptAndStyle'); > > > > > > > >On Fri, 2003-10-17 at 09:56, Luc Saint-Elie wrote: > > > Heelo, > > > > > > In order to try Remy Dufour code, I'm trying to use prefilter what I've > > > never done before. > > > > > > I have in smarty_dir/extraplugins/utils > > > the file prefilter.literalScriptAndStyle.php > > > > > > This file is (Remy's code) : > > > > > > <?php > > > /* > > > * Smarty plugin > > > * ------------------------------------------------------------- > > > * File: prefilter.literalScriptAndStyle.php > > > * Type: prefilter > > > * Name: literalScriptAndStyle > > > * Purpose: Add {literal} to style and script tags. > > > * ------------------------------------------------------------- > > > */ > > > function smarty_prefilter_literalScriptAndStyle(&$tpl_source, &$smarty) > > > { > > > // <javascript> > > > $pattern[] = > > > '~<script\b(?![^>]*smarty)(.*)</script>~iU'; > > > $replace[] = > > > > '<!--{literal}--><script$1>$2</script><!--{/literal}-->'; > > > > > > // <style> > > > $pattern[] = > > > '~<style\b(?![^>]*smarty)(.*)</style>~iU'; > > > $replace[] = > > '<!--{literal}--><style$1>$2</style><!--{/literal}-->'; > > > > > > > > > return preg_replace($pattern, $replace, $tpl_source); > > > } // function > > > ?> > > > > > > I have a smarty.config.php file containing > > > > > > // VARIOUS DEFINE.... > > > Class My_Smarty extends Smarty > > > { > > > /** > > > * Constructor > > > **/ > > > function My_Smarty () > > > { > > > $this->use_sub_dirs = true; > > > $this->compile_check = true; > > > $this->debugging = false; > > > $this->debugging_ctrl = 'NONE'; > > > $this->caching = false; > > > $this->template_dir = _APPLIPATH.'/templates'; > > > $this->compile_dir = _SMARTYPATH.'/templates_c'; > > > $this->config_dir = _SMARTYPATH.'/configs'; > > > $this->cache_dir = _SMARTYPATH.'/cache'; > > > $this->debug_tpl = _SMARTYPATH.'/debug.tpl'; > > > $this->cache_lifetime = 3600; > > > $this->plugins_dir = Array('plugins', > > > 'extraplugins/rss', > > > 'extraplugins/utils'); > > > > > $this->register_prefilter('smarty_prefilter_literalScriptAndStyle'); > > > } > > > } > > > > > > Result : > > > > > > Fatal error: Smarty error: [plugin] prefilter > > > 'smarty_prefilter_literalScriptAndStyle' is not implemented in > > > f:\easyphp\www\musiquemag_01\include\smarty\Smarty.class.php on line > 1895 > > > > > > I tried to place > > > > > > $smarty->register_prefilter('smarty_prefilter_literalScriptAndStyle'); > > > > > > in my index.php file > > > <?php > > > session_start(); > > > include 'include/smarty.config.php'; > > > $smarty = new My_Smarty; > > > $smarty->register_prefilter('smarty_prefilter_literalScriptAndStyle'); > > > ..... > > > > > > With the same result > > > > > > Luc > > -- > Smarty General Mailing List (http://smarty.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- > Smarty General Mailing List (http://smarty.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.smarty.general (#10378) next »