NAME

NTS::Template - Fast and small template system

Description

Formerly Ananke::Template, this Template System is based in Template ToolKit. Very small compared with Template Toolkit, and 100% compatible with mod_perl 2.

Speedy:

$ cd /proc ; grep name cpuinfo
model name      : AMD Athlon(tm) XP 1700+

$ ./bench_templ
Benchmark: timing 5000 iterations of NTS::Template, Template ToolKit...
NTS::Template:  9 wallclock secs ( 9.48 usr +  0.11 sys =  9.59 CPU) @ 521.38/s (n=5000)
Template ToolKit: 25 wallclock secs (24.84 usr +  0.16 sys = 25.00 CPU) @ 200.00/s (n=5000)

Memory:

$ ./GTop -m NTS::Template

NTS::Template
      Size     Shared       Diff
   2564096    1642496     114688 (bytes)

$ ./GTop -m Template

Template
      Size     Shared       Diff
   3960832    1683456    1470464 (bytes)

SYNOPSIS

no comment

TO DO

no comment

DIRECTIVE

IF, ELSIF OR ELSEIF, UNLESS

try:

$vars->{test1} = "ok";
$vars->{test2}->{test2} = "ok";
$vars->{test3} = 1;

[% IF test1 %] ok, test1 [% END %]
[% IF test2.test2 %] ok, test2.test2 [% END %]
[% IF test1 == test2.test2 %] ok, test1 == test2.test2 [% END %]
[% IF test1 == "ok" %] ok, test1 == "ok" [% END %]
[% IF test3 == 1 %] ok, test3 [% END %]
[% IF test1 AND test2.test2 AND test3 %] ok, test1 AND test2.test2 AND test3 [% END %]
[% IF test1 OR test3 %] ok, test1 OR test3 [% END %]
[% IF test1 == test3 %] ok, test1 == test3 [% ELSE %] fail [% END %]
[% IF test1 == test3 %] ok, test1 == test3 
[% IF test1 != "fail" %] ok, test1 != "ok" [% ELSE %] fail [% END %]
[% IF test2.test2 != "fail" %] ok, test2.test2 != "ok" [% ELSE %] fail [% END %]

[% IF test1 == test3 %] ok, test1 == test3
[% ELSIF test2.test2 == test3 %] ok, test2.test2 == test3 
[% ELSE %] fail [% END %]

[% UNLESS test1 == "fail" %] fail, test == "fail" [% ELSE %] ok [% END %]

return:

ok, test1 
ok, test2.test2 
ok, test1 == test2.test2 
ok, test1 == "ok" 
ok, test3 
ok, test1 AND test2.test2 AND test3 
ok, test1 OR test3 
fail
ok, test1 != "ok" 
ok, test2.test2 != "ok" 
fail
fail, test == "fail" 

FOREACH

Repeat the enclosed FOREACH ... END block for each value in the list.

[% FOREACH variable = list %]                 
    content... 
    [% variable %]
[% END %]

# or

[% FOREACH i = list_chn_grp %]
    [% count++ %]
    [% IF count % 2 %] [% bgcolor = "#FFFFFF" %]
    [% ELSE %] [% bgcolor = "#EEEEEE" %]
    [% END %]

    [% i.bgcolor %]
[% END %]

FOR

[% FOR i=1;i<=12;i++ %]
    [% i=1 %]
[% END %]

VARIABLES

[% var = 'text' %]
[% var %]

&PRINTF

[% var = 2 %]
[% &PRINTF('%02d',var) %]

&ESCAPE/&UNESCAPE

[% var = "http://www.nattis.com.br?a=b&c=d&e=f" %]
[% &ESCAPE(var,'') %]
[% &UNESCAPE(var,'') %]

Authors

  • Udlei Nattis E<lt>unattis (at) nattis.comE<gt>
    http://www.nattis.com