Re: Question about handling undefined variables

From: Date: Fri, 11 Jan 2002 15:34:15 +0000
Subject: Re: Question about handling undefined variables
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-2518@lists.php.net to get a copy of this message
--- Dan Thompson <djthompson@yahoo.com> wrote: > I am using Smarty for a system that I am building and am really > impressed > with what I have been able to do so far. But I have a question > about how to > handle undefined variables. What I have is a template that > resembles a form > that I am filling out. Because not all of the items may have > answers, the > PHP code before Smarty may or may not have defined/assigned all of > the > variables that are on the template. Therefore, when displaying the > processed > template, I receive error messages like "Warning: Undefined index: > description in ... on line ..." If you have a variable that is conditionally assigned, meaning only if certain programatic conditions are met, then you must assign it a default (in your case empty "") value. I find this to be much cleaner than using Smarty "if" statements . Here's an example: $tpl->assign("MY_VAR", ""); // assign as empty if($something == true) { // re-assign if condition is met $tpl->assign("MY_VAR", "New value"); } Brent __________________________________________________ Do You Yahoo!? Send FREE video emails in Yahoo! Mail! http://promo.yahoo.com/videomail/

« previous php.smarty.general (#2518) next »