RE: [htmltmpl] TMPL_IF truth vs definition
Brought to you by:
samtregar
From: Chris D. <Chr...@Ma...> - 2002-06-21 10:14:01
|
On Friday, June 21, 2002 3:14 UTC, Tugrul Galatali wrote: > [...] I had gotten into the habit of using TMPL_IF in the sense of if a variable is defined instead of if it is true. Now 99% of the time this just happens to work, as most defined things are also considered to be true. But that 1% needs to be dealt with. > I realize I could do this with H::T::Expr, but I don't want to go that far (and it would require changing a lot of templates ;). And I could start evaluating the defined condition in the code and exporting booleans, but that triggers the valid warning in the documentation about that. > The question I have is how to proceed: > 1) Add a flag to switch TMPL_IF to the alternate behaviour (if defined vs if true) > 2) Add another tag TMPL_IFDEF or similar. I don't really see why you can't take the pain and amend your CGI scripts. What documentation warnings are you referring to, that advise against this course of action? (I can see one warning against matching TMPL_IF to perl if statements, but that doesn't seem to apply.) Consider the H::T snippet, <TMPL_IF NAME="my_bool">...</TMPL_IF> In your CGI, instead of writing simply, { my_bool => $x } you would write something like this, { my_bool => defined $x } Here's a corresponding (trivial) truth table, from which you should be able to take the appropriate expressions: $x defined $x defined $x && $x defined $x && 1 --------------- --------------- --------------- --------------- undef undef "" "" 0 1 0 1 1 1 1 1 2 1 2 1 Chris -- Chris Davies, Manheim Online Tel. 0113 393-2004 Fax. 0870 444-0482. Mobile 07778 199069 |