I am working in template toolkit framework. I have got an perl hash datatype in my tt file. I want to convert this hash datatype to javascript hash datatype.
code: template:
[% PERL %]
use JSON qw(encode_json);
my $vars = {
'version' => 3.14,
'days' => [ qw( mon tue wed thu fri sat sun ) ],
'cgi' => CGI->new(),
'me' => {
'id' => 'abw',
'name' => 'Andy Wardley',
},
};
my $json = encode_json($vars->{'me'});
[% END %]
<script>
function callme(){
var me = [% $json %]
}
</script>
now i want the me hash to be accessible in javascript
This is version [% version %]
Id: [% me.id %] Name: [% me.name %] now i want the me hash to be accessible in javascript – Kalai Nov 23 '12 at 12:41