Re:Question about handling undefined variables
| From: | Brian E . Lozier | Date: | Fri, 11 Jan 2002 05:29:35 +0000 |
| Subject: | Re:Question about handling undefined variables | ||
| Groups: | php.smarty.general | ||
| Request: | Send a blank email to php-smarty-general+get-2516@lists.php.net to get a copy of this message | ||
{if isset($description)}
{$description}
{/if}
(it was in the message just previous to yours on this list :P)
----- Original Message -----
From: Dan Thompson <djthompson@yahoo.com>
To: smarty@lists.ispi.net
Date: 1/10/02 4:06:10 PM
>
>Hello,
>
>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 ..."
>
>My assumption would have been that Smarty would have handled this and output
>nothing if a variable was not assigned (maybe with an error in the popup
>debug console). But it doesn't, so I have tried the following
>
>1) {if $description neq ""} {$description} {/if}
>
>2) {$description | default: ""}
>
>3) {assign var="description" value=$description | default: ""}
>{$description}
>
>None of these work. They all produce the same error.
>
>Can somebody provide some advice on how to handle this situation? My guess
>is something simple that I am missing. Thanks.
>
>
>
>_________________________________________________________
>
>Do You Yahoo!?
>
>Get your free @yahoo.com address at http://mail.yahoo.com
>
>
>
>
>---
>You are currently subscribed to smarty as: brian@massassi.net
>To unsubscribe send a blank email to $subst('Email.Unsub')
>Visit Smarty's homepage at
>http://www.phpinsider.com/php/code/Smarty/