vti/text-haml

Don`t know how to pass array or hash to template

Opened this issue · 4 comments

That code

#!/usr/bin/perl
use Text::Haml;
%eth0 = ( mac => '10:fe:ed:f9:c4:b8', ip => 'dhcp' );
$haml = Text::Haml->new;
$haml->format('html5');
$page = $haml->render('%p= $eth0{mac}', eth0 => '%eth0') || die $haml->error;
print $page,"\n"; 

shows me

Global symbol "%eth0" requires explicit package name at (eval 10) line 1.

changing the eth0 => '%eth0' to %eth0 or 'eth0' in $haml->render() call doesn't resolve issue.
also can`t find anything about that case in the doc.

the code eth0 => %eth0 resolved the issue. Could that be added to readme?

Yes, render in the second parameter gets hash (not hashref). In first example template gets variable $mac and $ip.

And code
$page = $haml->render('%p= $eth0{mac}', eth0 => '%eth0') || die $haml->error;
should be replaced with
$page = $haml->render('%p= $eth0->{mac}', eth0 => %eth0) || die $haml->error;

I have updated the documentation and render render_file
TheAthlete@47d7923