The Tenjin templating system allows you to embed Perl code in your HTML templates.

Here is a sample template and a sample script:

The template:

examples/tenjin/templates/simple.html

<h1>[== $title ==]</h1>

[== join(" ", @$planets) =]

<ul>
<?pl for my $planet (@$planets) { ?>
   <li>[== $planet ==]</li>
<?pl } ?>
</ul>

[= time =]

The code to fill it:

examples/tenjin/tenjin.pl

use strict;
use warnings;
use Tenjin;
$Tenjin::USE_STRICT = 1;

my $tenjin = Tenjin->new({ path => ['templates'] });
print $tenjin->render('simple.html', {
    title => 'This is the title',
    planets => ['Earth', 'Mars', 'Jupiter'],
})


The resulting output:

examples/tenjin/output.html

<h1>This is the title</h1>

Earth Mars Jupiter

<ul>
   <li>Earth</li>
   <li>Mars</li>
   <li>Jupiter</li>
</ul>

1617688660