|
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 |
cablehead Smarty Rookie
Joined: 09 Jul 2003 Posts: 23
|
Posted: Thu Jul 31, 2003 1:29 pm Post subject: prefilters accessing smarty object variables |
|
|
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 |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Thu Jul 31, 2003 1:39 pm Post subject: |
|
|
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 |
|
cablehead Smarty Rookie
Joined: 09 Jul 2003 Posts: 23
|
Posted: Thu Jul 31, 2003 2:50 pm Post subject: |
|
|
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 |
|
|
|
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
|