As a workaround, I always add the following to my hash of template vars:
'as_list' => sub { return ref($_[0]) eq 'ARRAY' ? shift : [ shift ] }
Then I can do this in the template:
[%
FOR i = as_list( form.field('time_zone').options );
"value = $i.value, lable = $i.label\n" | stderr;
END;
%]
I had wanted to do this as a vmethod, but I needed it to work for lists
of objects, too, so a global function was the best I could come up with.
I guess this could be rolled into a plugin or something...
Bill Moseley wrote:
> IIRC, single element array refs get turned into single
> elements. But, I
> thought it was only an issue when returning lists and not list refs.
>
> Anyway, this code and template:
>
> warn "in perl\n";
> my @options = $self->field('time_zone')->options;
> warn Dumper [EMAIL PROTECTED];
>
> my $options = $self->field('time_zone')->options;
> warn Dumper $options;
>
> [%
> "in template\n" | stderr;
> USE Dumper;
> Dumper.dump( form.field('time_zone').options ) | stderr;
>
> FOR i = form.field('time_zone').options;
> "value = $i.value, lable = $i.label\n" | stderr;
> END;
>
> %]
>
>
> results in:
>
> in perl
> $VAR1 = [
> {
> 'value' => '1',
> 'label' => 'America/Los_Angeles'
> }
> ];
> $VAR1 = [
> {
> 'value' => '1',
> 'label' => 'America/Los_Angeles'
> }
> ];
>
> in template
> $VAR1 = {
> 'value' => '1',
> 'label' => 'America/Los_Angeles'
> };
>
>
> value = America/Los_Angeles, lable =
> value = 1, lable =
>
> Where there's two elements in the array it works as expected.
>
> in template
> $VAR1 = [
> {
> 'value' => '3',
> 'label' => 'America/Chicago'
> },
> {
> 'value' => '1',
> 'label' => 'America/Los_Angeles'
> }
> ];
> value = 3, lable = America/Chicago
> value = 1, lable = America/Los_Angeles
>
>
>
> --
> Bill Moseley
> [EMAIL PROTECTED]
>
>
> _______________________________________________
> templates mailing list
> [email protected]
> http://lists.template-toolkit.org/mailman/listinfo/templates
>
_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates