[Beginner] How to use prefilters ?
| From: | Luc Saint-Elie | Date: | Fri, 17 Oct 2003 14:56:04 +0000 |
| Subject: | [Beginner] How to use prefilters ? | ||
| Groups: | php.smarty.general | ||
| Request: | Send a blank email to php-smarty-general+get-10369@lists.php.net to get a copy of this message | ||
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