Hi Darren,
Wednesday, December 3, 2003, 10:07:00 AM, you wrote:
dc> * christopher <christopher at tokpela.com> [2003/12/03 09:40]:
>> This leaves no distinction between 0 and undef meaning you can never
>> turn off a default by number, you would always have to use literal
>> strings like on/off. Although the docs defer to Perl, is this the
>> desired result or should the DEFAULT directive allow the value of zero?
dc> This is the desired outcome.
Yes, but doesn't this seem a little counter-intuitive and not exactly
what you would expect from a DEFAULT variable? Seems like DEFAULTS
should be checking for definition vs. truth?
Like saying:
if a variable is defined/passed-in (whatever it is), use it
if not, use it's default, X.
Whereas, the current logic says:
if a variable is true (but not false), use it
if not, use it's default (which always fails if the variable is 0
or '0')
I can see this as only being an issue when trying to use 0 or the string '0'.
dc> You could pass some constants into your template:
dc> use Template;
dc> my $template = Template->new(CONSTANTS => { TRUE => 1, FALSE => 0 });
dc> $template->process(\*DATA) or die $template->error();
dc> And check against constants.TRUE and constants.FALSE instead of simply
dc> testing truth.
My tests show that this still will not work. The issue is
with definition vs. truth when setting variables or using the default
values.
use warnings;
use strict;
use Template;
my $template = Template->new(CONSTANTS => { TRUE => 1, FALSE => 0 },
PRE_CHOMP => 1);
$template->process(\*DATA) or die $template->error();
print "Done\n";
__DATA__
[% PROCESS document_page_default_true
show_section_default_true = constants.FALSE %]
[% PROCESS document_page_default_false
show_section_default_false = constants.TRUE %]
[% BLOCK document_page_default_true %]
[% DEFAULT
show_section_default_true = constants.TRUE %]
[% IF show_section_default_true == constants.TRUE %]
This is where the section is shown but incorrectly (default set to TRUE,
variable passed in FALSE)
[% ELSE %]
this section should not be shown
[% END %]
[% END %]
[% BLOCK document_page_default_false %]
[% DEFAULT
show_section_default_false = constants.FALSE %]
[% IF show_section_default_false == constants.TRUE %]
Correct, this section should be shown (default set to FALSE, variable passed in
TRUE)
[% ELSE %]
Incorrect, this section should not be shown
[% END %]
[% END %]
--
Best regards,
christopher mailto:[EMAIL PROTECTED]
_______________________________________________
templates mailing list
[EMAIL PROTECTED]
http://lists.template-toolkit.org/mailman/listinfo/templates