Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

prefilters accessing smarty object variables

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
cablehead
Smarty Rookie


Joined: 09 Jul 2003
Posts: 23

PostPosted: Thu Jul 31, 2003 1:29 pm    Post subject: prefilters accessing smarty object variables Reply with quote

Just working on a prefilter that will cater for second delimiter. I'm having trouble though accessing smarty variables from within the prefilter. This might be more a php thing -
Here's the code:

Code:

function smarty_prefilter_secondDelimiters($tpl_source, &$smarty) {

        print "a".$smarty->second_left_delimiter."<br>";
        print "c".$smarty->left_delimiter."<br>";

        return $tpl_source;
}

$smarty = new Smarty;

$smarty->left_delimiter = "<!--[";
$smarty->right_delimiter = "]-->";

$smarty->second_left_delimiter = "[";
$smarty->second_right_delimiter = "]";

print "p".$smarty->second_left_delimiter."<br>";

$smarty->register_prefilter("smarty_prefilter_secondDelimiters");

$smarty->display( ... );


The print statements prepended with p&c print ok, but the a prepended print shows a<br>.

That is the second delimiter doesn't seem to be available in the prefilter, but can be seen outside of the prefilter. The first delimiter can be seen inside the prefilter.

Any help is greatly appreciated,

Andy.
Back to top
View user's profile Send private message Send e-mail
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Thu Jul 31, 2003 1:39 pm    Post subject: Reply with quote

the object passed to your prefilter as $smarty is actually not the $smarty whose display-method was called, but an instance of the Smarty_Compiler class.

an ugly quick fix would be:
[php:1:3f60cf9933]
function smarty_prefilter_secondDelimiters($tpl_source, &$compiler) {
global $smarty;

print "a".$smarty->second_left_delimiter."<br>";
print "c".$smarty->left_delimiter."<br>";

return $tpl_source;
}
[/php:1:3f60cf9933]

unfortunately i don't know a nicer solution without modifying Smarty.class.php
Back to top
View user's profile Send private message Send e-mail Visit poster's website
cablehead
Smarty Rookie


Joined: 09 Jul 2003
Posts: 23

PostPosted: Thu Jul 31, 2003 2:50 pm    Post subject: Reply with quote

cheers messju.

I just came across your post outlining a new release of smarty which will allow member functions to be passed to prefilters. When this comes out it should allow for a cleaner solution this problem. I might just hard code the delimiters till it does.

Andy.
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    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