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

Replace Output in Smarty 2.6

 
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
bastimm21
Smarty n00b


Joined: 03 Jun 2015
Posts: 2

PostPosted: Wed Jun 03, 2015 6:19 pm    Post subject: Replace Output in Smarty 2.6 Reply with quote

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
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Thu Jun 04, 2015 12:12 am    Post subject: Reply with quote

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
View user's profile Send private message
bastimm21
Smarty n00b


Joined: 03 Jun 2015
Posts: 2

PostPosted: Fri Jun 05, 2015 3:59 am    Post subject: Reply with quote

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
View user's profile Send private message
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