if (!passed_in_MY_BOOL_D1){
  MY_BOOL_D1 = 1
}
 
does'nt quite cut it,  because if I pass in a '0', the if evaluates to true and MY_BOOL_D1 gets 1. So the value that gets assigned is the inverse of what is passed in.

 
On 11/16/05, Josh Rosenbaum <[EMAIL PROTECTED]> wrote:
Subbu Meiyappan wrote:
> [%# ---------- file1.tt < http://file1.tt/> ----------%]
> [% DEFAULT
>       MY_BOOL_D0 = 0,
>       MY_BOOL_D1 = 1,
>       MY_INT_D10   = 10 %]
>
> Print Values:
> MY_BOOL_D0 = $MY_BOOL_D0
> MY_BOOL_D1 = $MY_BOOL_D1
> MY_BOOL_D10 = $MY_BOOL_D10
> [%# ---- End of file1.tt <http://file1.tt/> --------- %]
> i.e the boolean values that had a default of 1 could not be overridden
> from the calling template. All other values/types were overridable. Any
> ideas?

From the docs:
"The DEFAULT directive is similar to SET but only updates variables that are currently undefined or have no "true" value (in the Perl sense)."
http://www.template-toolkit.org/docs/plain/Manual/Directives.html

The part to note there is the last part about having no "true" value (in the Perl sense). Which means, '', 0 and undef.

The reason is that default is doing something like this:

if (!passed_in_MY_BOOL_D1){
MY_BOOL_D1 = default_MY_BOOL_D1
}

Since the ! evaluates to true when passed_in_MY_BOOL_D1 is 0, you would see the behavior you saw.

-- Josh

Reply via email to