Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

Register Prefilter doesn't work

 
Post new topic   Reply to topic    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
iriePub
Smarty Regular


Joined: 16 Jun 2006
Posts: 53

PostPosted: Fri Aug 18, 2006 8:39 am    Post subject: Register Prefilter doesn't work Reply with quote

Hi,
I have an extended Smarty Class to use register Plugins and Filters directly in the Konstruktor!
So I have the following:

[php:1:86248c7bff]
/**
* Dynamischer Block
*
* alles zwischen {dynamic} und {/dynamic} wird nie gecached
*/
function smarty_block_dynamic($param, $content, &$smarty) {
return $content;
}

/**
* Strip Block
*
* Alle Newslines, Tabs, Wagenrückläuft und Leerzeichen werden innerhalb
* von {strip2space} und {/strip2space} durch 1 Leerzeichen ersetzt
*/
function smarty_block_strip2space($param, $content, &$smarty) {
return preg_replace('~\s+~i', ' ', $content);
}

// Eigene Smartyklasse, die ich später
// mit weiteren Methoden erweitern kann
class MySmarty extends Smarty {

/**
* Konstruktor
*
* @param void
* @return void
*/
function MySmarty()
{
// Block, der nie gecached wird
$this->register_block('dynamic', 'smarty_block_dynamic', false);

// BLock, der zu einer Zeile zusammengeschmolzen wird
$this->register_block('strip2space', 'smarty_block_strip2space', false);



$this->autoload_filters = array(
#'output' => array('trimwhitespace') // Whitespaces etc entfernen!
);
}
}
[/php:1:86248c7bff]

This works very well. All Blocks / Filters are loaded and used correctly. Now I want to register a prefilter, that shows the templatename in the output. So I place a File
with this content into the plugins directory: prefilter.inserttplnames.php

[php:1:86248c7bff]
<?php
/*
* Smarty plugin
* --------------------------------------------------------
* File: prefilter.inserttplnames.php
* Type: prefilter
* Name: inserttplcomment
* Version: 1.0
* Date: 03 Jun 2006
* Purpose: Add Comment with Teplatename at begin & end of
* included tpl
* Install: Place in your (local) plugins directory and
* add the call:
* $smarty->load_filter('pre', 'inserttplnames');
* Author: Jens-André Koch
* --------------------------------------------------------
*/
function smarty_prefilter_inserttplnames($tpl_source, &$smarty)
{
return "\n<!------| Start of {\$smarty.template} |------>\n" . $tpl_source . "\n<!------| End of {\$smarty.template} |------>\n";
}
[/php:1:86248c7bff]
and call it in the Konstruktor og MySmarty Class like this:

[php:1:86248c7bff]
// Templates-Namen einfügen
$this->load_filter('pre', 'inserttplnames');
[/php:1:86248c7bff]

But it doesn't work. I already tried to register it via

[php:1:86248c7bff]
$this->register_prefilter('inserttplnames');
and
$this->autoload_filters = array('pre'=>array('inserttplnames'));
[/php:1:86248c7bff]
Both didn't work. Even if I place the filter-functions-code directly into the file where the class is declared.

For debugging reasons, I wrote "die('BLALBLA');" into the function. As my site loads normally, I see, the filter does not get laoded ...

Why? What's wrong?

Thanks!!
Back to top
View user's profile Send private message
iriePub
Smarty Regular


Joined: 16 Jun 2006
Posts: 53

PostPosted: Fri Aug 18, 2006 8:41 am    Post subject: Reply with quote

Something else: I tried to use the example from the manual:
http://smarty.php.net/manual/en/advanced.features.prefilters.php
but the function remove_dw_comments isn't loaded at all ...
Back to top
View user's profile Send private message
iriePub
Smarty Regular


Joined: 16 Jun 2006
Posts: 53

PostPosted: Fri Aug 18, 2006 9:13 am    Post subject: Reply with quote

Oh, I had to turn on force_compile, that did the trick. But one thing:

I find now everywhere this:

Code:

<!------| Start of {$smarty.template} |------>


Does this var not exist?

Edit: I had to use my own delimiter ... now it works!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP