[Templates] Getting keys from a hash

Karl Dane karl at rince.net
Tue Feb 26 11:00:20 GMT 2008


I guess my example wasn't a very good one - I just wanted to demonstrate 
that I was getting _nothing_ when using the keys method. If it had 
worked as expected, then it should have returned something like 
'ARRAY(0x8a8ca58)'

I keep playing, and so far any vmethods I use on the hash don't seem to 
work.

e.g.
[% cgihash.size %] returns nothing.
But [% list = [1 .. 10] %][% list.size %] returns '10' as you'd expect.



Neo [GC] wrote:
> Hi,
> 
> this may help you:
> 
> [% FOR entry IN cgihash %]
> key is: [% entry.key %]
> value is: [% entry.value %]
> [% END %]
> 
> 
> Greets,
> Thomas Weber / Neo [GC]
> 
> 
> Karl Dane schrieb:
>> This should be stunningly easy, but for some reason the 'keys' VMethod 
>> is giving me nothing.
>>
>> My template:
>> ---
>> should tell me this is a hash:
>> [% cgihash %]
>>
>> dump out the contents of the hash:
>> [% USE Dumper %]
>> [% Dumper.dump(cgihash) %]
>>
>> Now give me the keys:
>> [% cgihash.keys %]
>>
>> [[ TEMPLATE ENDS ]]
>>
>> ---
>> Output:
>>
>>    should tell me this is a hash:
>> HASH(0x88303dc)
>>
>> dump out the contents of the hash:
>>
>> $VAR1 = {
>>            'a' => 'newentry',
>>            'newbooking' => '1',
>>            'day' => '06',
>>            'monthdigit' => '02',
>>            'year' => '2008',
>>            'room' => '9',
>>            'gender' => 'male',
>>            'beds' => '3',
>>            'nights' => '2',
>>            'submit' => 'Book'
>>          };
>>
>>
>> Now give me the keys:
>>
>>
>> [[ TEMPLATE ENDS ]]
>>
>>
>> Also no joy with cgihash.sort or cgihash.list('keys').
>>
>> Can someone please tell me what I'm doing wrong?
>>
>> Thanks!
>>
>> Karl
>>
>> _______________________________________________
>> templates mailing list
>> templates at template-toolkit.org
>> http://mail.template-toolkit.org/mailman/listinfo/templates
>>   
> 
> _______________________________________________
> templates mailing list
> templates at template-toolkit.org
> http://mail.template-toolkit.org/mailman/listinfo/templates



More information about the templates mailing list