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 ]]
Apparently not! Still gives me nothing...
It's like the keys vmethod is being completely ignored.
Simon Wistow wrote:
> On Tue, Feb 26, 2008 at 10:22:02AM +, Karl Dane said:
>> Now give me the keys:
>> [% cgihash.keys %]
>
> Might [% cgihash.keys.join("\n") %] help here?
>
>
>
> _
On Tue, Feb 26, 2008 at 10:22:02AM +, Karl Dane said:
> Now give me the keys:
> [% cgihash.keys %]
Might [% cgihash.keys.join("\n") %] help here?
___
templates mailing list
templates@template-toolkit.org
http://mail.template-toolkit.org/mailman/li
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
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
Right! So - there's something REALLY weird going on here...
To answer Simon, cgihash is from perl's CGI lib: my $cgi = new CGI; my
$cgihash = $cgi->Vars;
Shouldn't be anything odd about it. But obviously it's behaving
differently for some reason.
New example. cgihash continues to act as before
On Tue, Feb 26, 2008 at 11:00:20AM +, Karl Dane said:
> 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)'
Where
On Tue, Feb 26, 2008 at 10:47:15AM +, Karl Dane said:
> Apparently not! Still gives me nothing...
>
> It's like the keys vmethod is being completely ignored.
Hmm, weird.
On my machine
% cat foo.tt
[%- cgihash = { 'a' => 1, 'b' => 2, 'c' => 3 } -%]
[% cgihash.keys.join("\n") %]
% tpage foo.t
On Tue, Feb 26, 2008 at 11:17:44AM +, Karl Dane said:
> Right! So - there's something REALLY weird going on here...
>
> To answer Simon, cgihash is from perl's CGI lib: my $cgi = new CGI; my
> $cgihash = $cgi->Vars;
>
> Shouldn't be anything odd about it. But obviously it's behaving
> diffe
Karl Dane <[EMAIL PROTECTED]> writes:
> Right! So - there's something REALLY weird going on here...
>
> To answer Simon, cgihash is from perl's CGI lib: my $cgi = new CGI; my
> $cgihash = $cgi->Vars;
Ouch. So there *is* indeed something special about $cgihash: It is
a tied hash, tied to the CGI
Terrific! That did the job.
I've used $cgi->Vars for ages and never had this trouble before. Guess
I'd never tried to do this before.
Thanks everyone for all your help.
Karl
Ash Berlin wrote:
> Vars does crazy tied stuff:
>
>> Many people want to fetch the entire parameter list as a hash in
On Tue, 2008-02-26 at 11:00 +, Karl Dane wrote:
> 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)'
... which is
> Tied variables behave strange in some aspects, and I guess this is one
> of them. I think that TT gets stuck when trying to find out whether
> cgihash is an object which implements a 'keys' method or a hash which
> should respond to the 'keys' vmethod.
action at a distance. nasty...
___
No wonder I came a cropper!
I'd kinda ignored the CGI aspect, as usually if you've got something
more than just a plain and simple data structure it shows up as such in
Data::Dumper. Since it looked like a plain old hash, I treated it as a
plain old hash.
Thanks again, everyone!
Karl
Clinto
Maybe, rather than rolling your own hookup to CGI, you should look at
the CGI plugin for TT:
http://template-toolkit.org/docs/modules/Template/Plugin/CGI.html
It has code to avoid the exact issue you ran into. One extra method that
does what you need.
METHODS
<#>
In addition to
15 matches
Mail list logo