Re: Test variable for falsiness without generating a warning
Andy Brook <[email protected]> Tue, 5 Jan 2021 17:09:58 +0000
| Newsgroups | gmane.comp.jakarta.velocity.user |
|---|---|
| Message-ID | <CACVGzMZS-JtCQH6O8N-fjbDdhTmAzc1vmL04wFuji0su1wWQnQ@mail.gmail.com> |
--00000000000069e30705b82a47d1 Content-Type: text/plain; charset="UTF-8" Use the fuzzy match, its cumbersome in some cases as it can involve repeating the same operation, your case, easy: #if ($!value && true == $value) do stuff #else ... The user guide doesn't really pull that out in the "if / else" block, look for: this is $!foo ## renders to "this is " without an exception On Tue, 5 Jan 2021 at 15:40, Christopher Schultz < [email protected]> wrote: > All, > > I've got a template where a variable may be either undefined or false > (or other values) and I'm specifically trying to determine if it's > *false*. My template code looks like this: > > #if($value && true == $value) > do stuff > #elseif(false == $value) > do other stuff > #end > > I don't seem to be able to get rid of the warning in the log file if > $value is actually null. > > Is it possible? Typically, you'd do something like: > > > #if($value) > stuff when value is defined and/or truthy > #else > stuff when value is undefined and/or falsey > #end > > But I'm interested in telling the difference between (boolean) false and > 'undefined'. > > Any ideas? Or should I just live with the log message? In production, > these things don't generate logs, but in development they do. I'd just > like to reduce the noise in dev if possible. > > -chris > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > > -- Andy Brook --00000000000069e30705b82a47d1--