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

eval modifier plugin

 
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 -> Plugins
View previous topic :: View next topic  
Author Message
johannes
Smarty Regular


Joined: 10 May 2003
Posts: 85
Location: Malmö, Sweden

PostPosted: Tue Mar 16, 2004 11:17 pm    Post subject: eval modifier plugin Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
Alexey
Smarty Rookie


Joined: 10 Nov 2003
Posts: 11
Location: Marburg, Germany

PostPosted: Fri Apr 23, 2004 2:46 pm    Post subject: Reply with quote

Do you have any idea how to do it without globals?
Code:
global $smarty;

I wondering that $smarty is not passed to modifier plugins... Crying or Very sad
Back to top
View user's profile Send private message
messju
Administrator


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

PostPosted: Fri Apr 23, 2004 4:23 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
Alexey
Smarty Rookie


Joined: 10 Nov 2003
Posts: 11
Location: Marburg, Germany

PostPosted: Mon Apr 26, 2004 7:18 am    Post subject: Reply with quote

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
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 -> Plugins 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