|
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 |
wo Smarty n00b
Joined: 17 Nov 2007 Posts: 3
|
Posted: Sat Nov 17, 2007 11:38 pm Post subject: Assignment operator |
|
|
I wish there was an assignment operator:
Code: | {variable := custom_plugin_call(arg1=value1, arg2=value2 ...)} |
I find this prettier than :
Code: | {capture assign=variable}{custom_plugin_call arg1=value1 arg2=value2 ...}{/capture} |
Custom instrumentation of plugin could allow this:
Code: | {custom_plugin_call assign=variable arg1=value1 arg2=value2} |
but it's not much better
I don't intend to wait on that feature to be implemented. It can be easily emulated using a prefilter. Implementation of such a prefilter is left as an exercise for the writer, and the reader if she's interested. |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Wed Nov 28, 2007 9:02 pm Post subject: |
|
|
{custom_plugin_call assign=variable arg1=value1 arg2=value2} is the usual -- meaning that the assignment capability is left as an implementation detail of the plugin. You can create a custom modifier to do similar (though it will probably need to be manually registered and perhaps live as a method on your extended Smarty class so that it can get a reference to the current smarty instance).
With such a beast you could then do something like:
{custom_plugin_call|assign:variable arg1=value1 arg2=value2} |
|
Back to top |
|
wo Smarty n00b
Joined: 17 Nov 2007 Posts: 3
|
Posted: Mon Dec 03, 2007 11:02 am Post subject: |
|
|
Quote: | the assignment capability is left as an implementation detail of the plugin |
Don't you thing that such a facility should be addressed in a standard manner by Smarty ? This wouldn't prevent developpers from addressing custom assignments needs using the then-standardized "assign" parameter.
I'm still dubious about how to properly implement such a nice syntax bonus (perhaps in the form of a compiler plugin) without hacking Smarty/Smarty_Compiler internals.
Perhaps someone have an idea about a nice, easy to use, relatively easy to implement, way of providing assignment to template authors. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Dec 03, 2007 2:29 pm Post subject: |
|
|
Quote: | Don't you thing that such a facility should be addressed in a standard manner by Smarty |
Actually no. Ideally, the template designer shouldn't be assigning anything to template vars, they should just use what is given to them. Even {assign} can be a borderline case. Any time variable assignment happens in templates, you start to cross the line of the application/presentation separation.
Custom plugins can handle their own assignments, and that is a good thing. |
|
Back to top |
|
wo Smarty n00b
Joined: 17 Nov 2007 Posts: 3
|
Posted: Mon Dec 03, 2007 4:40 pm Post subject: |
|
|
[quote]Ideally, the template designer shouldn't be assigning anything to template vars, they should just use what is given to them.[/b]
Sure. Perhaps another scope for template assigned variables would solve the problem. That way, template assigned variables couldn't erase regular template variables. More, template assigned variables couldn't be accessed using get_template_vars(), which would help keep the application/presentation separation (preventing presentation data to reenter the application somehow). |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Dec 03, 2007 4:44 pm Post subject: |
|
|
Config file vars kind of fill this gap. They are static values though. |
|
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
|