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

handle to smarty within modifier?

 
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 -> Tips and Tricks
View previous topic :: View next topic  
Author Message
gucki
Smarty n00b


Joined: 09 Mar 2005
Posts: 4

PostPosted: Wed Mar 09, 2005 9:21 pm    Post subject: handle to smarty within modifier? Reply with quote

hi!

i just wrote a modifier but had to make a function out of it, because i didnt find a solution to get a handle to the calling smarty instance. is there any way to get the handle or do i need to make a function for that?

by the way, is it possible to make the |@modifier instead of |modifier the default? i didnt see any config-switch in smarty.class.php for that, but it would be really nice, as the overhead used by doing only |modifier could mostly (95% of all vars passed are no arrays) skipped.

gucki
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Wed Mar 09, 2005 9:32 pm    Post subject: Re: handle to smarty within modifier? Reply with quote

gucki wrote:
i just wrote a modifier but had to make a function out of it, because i didnt find a solution to get a handle to the calling smarty instance. is there any way to get the handle or do i need to make a function for that?


It is possible, but you will have to give up auto-loading of the modifier (unless you are willing to use some sort of convention like a public var or a public slass that loads a singleton instance -- but that tends to be application specific). The easiest is probably to create the modifier as a method of smarty (or better, your extended smarty class) and manually register it. Then you get access to the smarty instance using $this.

There are threads already discussing this; for a real example, see the second post in this thread: http://www.phpinsider.com/smarty-forum/viewtopic.php?t=3387

gucki wrote:
by the way, is it possible to make the |@modifier instead of |modifier the default? i didnt see any config-switch in smarty.class.php for that, but it would be really nice, as the overhead used by doing only |modifier could mostly (95% of all vars passed are no arrays) skipped.


Probably not. Its been that way for a very long time. A config switch for that sounds like a very bad idea to me.

BTW: for future reference, the Tips & Tricks forum is not intended for questions but rather solutions.
Back to top
View user's profile Send private message
gucki
Smarty n00b


Joined: 09 Mar 2005
Posts: 4

PostPosted: Thu Mar 10, 2005 8:26 am    Post subject: Reply with quote

hi and thanks a lot for the modifier stuff!

hm, why not add such a switch to finetune the smarty-compiler? there are already some switches like 'left_delimiter' which affect the compiler behavior. i agree that changing the default behavior might cause some guys to get angry with me Wink

gucki
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Thu Mar 10, 2005 8:29 pm    Post subject: Reply with quote

Think of things like left_delimiter as the same thing as PHP's open tag. It is needed mainly for integration with other systems. For very good reasons, PHP offers no way to change the syntax of operators like "->" and "=>" and others. The syntax may be arbitrary but it is important that it remains consistent. Same applies to Smarty.

Feel free to go ahead an write a drop-in-replacement for the existing compiler (perhaps even just subclass it). Just don't expect that you or your befuddled users will be able to get any help from the community. That's but one of the key points -- if syntax switches are introduced, it becomes near impossible to provide support.

Best Regards
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 -> Tips and Tricks 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