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

Optional template variables?

 
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 -> Feature Requests
View previous topic :: View next topic  
Author Message
daniel_james
Smarty n00b


Joined: 01 Jul 2009
Posts: 2
Location: Denver, CO USA

PostPosted: Fri Jul 03, 2009 8:42 pm    Post subject: Optional template variables? Reply with quote

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 Sad
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. Wink

Thanks.
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 -> Feature Requests 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