plSmarty is a lightweight template engine that uses a subset of Smarty's tags.

An example

A page that uses plSmarty is made up of two things : on one hand a template which contains HTML code and some Smarty tags and on the other hand a Perl script. The example that follows dumps the current environment variables.

The template

Here is the content of the env.tpl template:

{include file='header.tpl'}

<h1>
  Dump of environment variables
</h1>

<table class="light">
<tr>
  <th>variable</th>
  <th>value</th>
</tr>

{foreach from=$envs item=myenv}
<tr>
  <td><b>{$myenv[0]}</b></td>
  <td>{$myenv[1]}</td>
</tr>

{/foreach}
</table>

{include file='footer.tpl'}                                

The Perl code

The corresponding Perl code in index.tpl that displays the page is:

use plSmarty;
print header("text/html");
my $page = new plSmarty;

# display the page
$page->assign('page',"Environment variables");
foreach my $key (sort keys %ENV) {
  $page->append('envs',($key,$ENV{$key}));
}
$page->display("env.tpl");