|
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 |
daniel_james Smarty n00b
Joined: 01 Jul 2009 Posts: 2 Location: Denver, CO USA
|
Posted: Fri Jul 03, 2009 8:42 pm Post subject: Optional template variables? |
|
|
It's quite common to see this message when the 'bar' index wasn't assigned to the $foo array before display() was called:
Notice: Undefined index: bar in file.php on line 17
This can be helpful in that it can indicate that the programmer and template designer aren't on the same page; but often the index is intentionally not assigned, and the resulting error message necessitates more work to hide.
Right now the only options are:
1. Programmer sets $smarty->error_reporting = 0; //which requires debugging to be turned off
2. Programmer manually assigns a null value to each index that the template expects.
3. Template designer writes {if $foo.bar}{$foo.bar}{/if} for each template variable.
Most probably go for the third option, but I think that's repetitive and unnecessary. All that's really needed is the ability avoid these messages through smarty, either on a per-variable basis like this:
{$foo.bar optional=true}
Or globally like this:
$smarty->optional_vars = true;
I think this would only require some extra logic to be inserted when the template is compiled, something like this:
$foo['bar'] = isset($foo['bar'])?$foo['bar']:null;
Please consider this. I think such a feature would save a lot of people a lot of work. More than that, this would facilitate a greater degree of loose coupling between business logic and presentation logic (which is the goal of smarty right?).
If you think this is a bad idea, please, by all means shoot it down.
Thanks. |
|
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
|