|
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 |
kaitlyn2004 Smarty Regular
Joined: 26 Apr 2007 Posts: 47
|
Posted: Mon May 02, 2011 3:20 pm Post subject: Plugin parameter without value? |
|
|
Getting a smarty error when I want to add a function parameter without a value. Smarty core has this with the "nocache" option...
why can't I have {my_custom_function my_param}
Not every param needs a value... it's a flag of sorts...
would expect $params['my_param'] = NULL; |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Mon May 02, 2011 4:57 pm Post subject: |
|
|
Smarty3 does have some fix option flags like "nocache" which need no value.
Also it does implement shorthand syntax for build in tags where you don't need the attribute names if you use the standard parameter ordering.
For example instead of
{assign var='foo' value='bar'}
you could use
{assign 'foo' 'bar'}
This works because Smarty does know for the build in tags which parameter are required and which are optional.
However at plugins the compiler has no knowledge about the number and kind of parameter. So shorthands or custom option flags like in your request could and up in an ambiguos syntax. |
|
Back to top |
|
bimal Smarty Elite
Joined: 19 Apr 2007 Posts: 423
|
Posted: Wed May 25, 2011 8:01 am Post subject: do you want to omit the parameter in the function body? |
|
|
I too thought of the same, initially.
Code: | $params['my_param'] = NULL; |
If you want that ALWAYS inside your template, then there is no worth of passing it in your function. Templates are not dynamic. But you can check the parameters inside the function body.
Code: | $params['my_param'] = isset($params['my_param'])?$params['my_param']:null; |
If you add this line in the top of your function body, you are free to omit my_param in the template function. |
|
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
|