#!/usr/bin/env perl
use strict;
use warnings;
use CGI;
use Template;
use FindBin qw($Bin);
use constant TEMPLATE_PATH => "$Bin/";
(my $template = __FILE__) =~ s/\.pl$/.tt/; # Derive the template from the script name.
my $data = {list => [qw(foo bar baz)]};
render($template, $data);
sub render {
my ($temp, $data) = @_;
my $t = Template->new({INCLUDE_PATH => TEMPLATE_PATH})
|| die "$Template::ERROR\n";
$t->process($temp, $data) || die $t->error, "\n";
}
####
Hello world
[%- FOR string IN list %]
-
----[% string %]----
[%- END %]
####
Hello world
-
----foo----
-
----bar----
-
----baz----
####
use strict;
use warnings;
use CGI;
use Mojo::Template;
use FindBin qw($Bin);
use constant TEMPLATE_PATH => "$Bin/";
(my $template = __FILE__) =~ s/\.pl$/.tt/; # Derive the template from the script name
my $data = {list => [qw(foo bar baz)]};
render($template, $data);
sub render {
my ($temp, $data) = @_;
print Mojo::Template
->new(vars => 1)
->render_file(TEMPLATE_PATH . $temp, $data);
}
####
Hello world
% for my $string (@$list) {
-
----<%= $string %>----
% }
####
#!/usr/bin/env perl
use strict;
use warnings;
use CGI qw(:standard);
my $data = {list => [qw(foo bar baz)]};
print start_html(-title => "Hello world");
print ul(
map{
li(
div({class => 'inforno'}, "----$_----")
) . "\n"
} @{$data->{'list'}}
);
print end_html();