|
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 |
bastimm21 Smarty n00b
Joined: 03 Jun 2015 Posts: 2
|
Posted: Wed Jun 03, 2015 6:19 pm Post subject: Replace Output in Smarty 2.6 |
|
|
Hello,
i am just writing a plugin for a webproject, which uses Smarty 2.6.28.
There i need to replace the output.
at the moment i use this code:
Code: |
function replaceSmarty($tpl_output, &$smarty){
$replace = "test";
$tpl_output = str_replace("searchString", $replace , $tpl_output);
return $tpl_output;
}
//die($smarty->_version); //2.6.28
$smarty->register_outputfilter("replaceSmarty");
|
this works fine.
But now i have to change the $replace variable with content from outside of the replaceSmarty-function. But i cant access any variables outside of this function....
Can somebody give me a small hint, how to get the data from outside?
Other thing: is this outputfilter fast? or is there a faster method to replace the output?
thanks in advance |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Thu Jun 04, 2015 12:12 am Post subject: |
|
|
Assign the $replace as template variable like
Code: | $smarty->assign('replace',$replace); |
In your output filter you can get its value with
Code: | $replace = $smarty->get_template_vars('replace'); |
|
|
Back to top |
|
bastimm21 Smarty n00b
Joined: 03 Jun 2015 Posts: 2
|
Posted: Fri Jun 05, 2015 3:59 am Post subject: |
|
|
THX!!
i found an other solution, which (i think) should be faster:
first i declare a constant e.g. (define("REPLACE", "replaceText");
and than i can use this in the function. So i dont need to use the smarty variable. |
|
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
|