|
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 |
johannes Smarty Regular
Joined: 10 May 2003 Posts: 85 Location: Malmö, Sweden
|
Posted: Tue Mar 16, 2004 11:17 pm Post subject: eval modifier plugin |
|
|
Hi, use this modifier to be abel to write Smarty-tags inside a text that you get from a database, Hope this will work for you!
Code: | /*
* Smarty plugin
* -------------------------------------------------------------
* File: modifier.do_eval.php
* Type: modifier
* Name: do_eval
* ver 0.1.0
* date: 2004-03-16
* Purpose: run eval, enable Smartytags inside txt filelds from db
* -------------------------------------------------------------
*/
/* {$data|do_eval} */
function smarty_modifier_do_eval($doc) {
global $smarty;
$smarty->assign('doc_to_eval', $doc);
$evald = $smarty->fetch('eval.tpl');
return $evald;
} |
eval.tpl
Code: | {eval var=$doc_to_eval} |
/Johannes _________________ --------------------------
nice culture on the Internet
www.poeter.se |
|
Back to top |
|
Alexey Smarty Rookie
Joined: 10 Nov 2003 Posts: 11 Location: Marburg, Germany
|
Posted: Fri Apr 23, 2004 2:46 pm Post subject: |
|
|
Do you have any idea how to do it without globals?
I wondering that $smarty is not passed to modifier plugins... |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Fri Apr 23, 2004 4:23 pm Post subject: |
|
|
Alexey wrote: | Do you have any idea how to do it without globals? |
extend class smarty and register the modifier as an object's method.
or register the modifier as a static method of any class. inside this static method $this will become a reference to (the calling) smarty-object then. |
|
Back to top |
|
Alexey Smarty Rookie
Joined: 10 Nov 2003 Posts: 11 Location: Marburg, Germany
|
Posted: Mon Apr 26, 2004 7:18 am Post subject: |
|
|
Right. I always register plugins within Smarty extention class. But I always used &$smarty parameter before in order to make profit of the Smarty functionality. Obviously in this case &$smarty is the pointer to the same instance as $this. Fine! |
|
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
|