|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
lstelie Smarty Rookie
Joined: 17 Oct 2003 Posts: 9 Location: Paris France
|
Posted: Fri Oct 17, 2003 4:17 pm Post subject: How to use prefilter ? |
|
|
Heelo,
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 :
<?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('literalScriptAndStyle');
}
}
Result :
Fatal error: Smarty error: [plugin] prefilter 'smarty_prefilter_literalScriptAndStyle' is not implemented in f:\easyphp\www\PATH_TO_SMARTYDIR\Smarty.class.php on line 1895
I tried to place
$smarty->register_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 |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Fri Oct 17, 2003 5:01 pm Post subject: |
|
|
The register_prefilter() function is to register an existing function as a prefilter, whereas load_filter() will instruct a filter to be loaded from the plugin directory and registered. So in your case:
$smarty->load_filter('pre','literalScriptAndStyle');
should work. |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|