TemplatePower PERL module
TemplatePower is a lightweight templating system for Perl which includes nested block support. As most templating systems, it’s main purpose is to seperate program code from layout of the output.
TemplatePower is basically an expanded straightforward Perl port of PHP class TemplatePower (release 1.6.2) and offers full template-compatibility.
License
TemplatePower is published under the Perl Artistic License 2.0.
System requirements
Any machine running Perl 5.x
Included files
- demo.pl: Demo script.
- demo.tpl: Demo template
- demo1622.pl: Demo script for the new functions of 1.6.2.2
- demo1622.tpl: Demo template for the new functions of 1.6.2.2
- TemplatePower.pm: TemplatePower Perl module
Usage
For a detailed description and examples of how to use TemplatePower, see the demo files or check out the original TemplatePower website.
TemplatePower Methods
new(templatefile)
prepare()
showUnAssigned([TRUE|FALSE])
assign([blockname].variablename, value)
assignGlobal(variablename, value)
assignInclude(templatefile)
gotoBlock(blockname)
newBlock(blockname)
getOutputContent()
printToScreen()
printVars()
hasBlock(blockname)
getBlockList()
getVarList(blockname)
getVarValue([blockname.]variablename)
setVarStartEnd(startDelimiter, endDelimiter)
setVarStartEnd has to be called BEFORE preparing the template, otherwise it will have no effect!
getVarStartEnd()
getVersion()
TemplatePower Templates
Variables
{variablename}
Blocks
<!-- START BLOCK : blockname -->
whatever should be in the block
<!-- END BLOCK : blockname -->
TemplatePower Demo
Demo code:
use strict;
use warnings;
use TemplatePower;
my $tpl=TemplatePower->new('mini.tpl');
$tpl->prepare();
for (my $i=1; $i<999; $i++) {
$tpl->newBlock('row');
$tpl->assign('count', $i);
}
$tpl->printToScreen();
Demo template:
<!-- START BLOCK : row -->
This is row #{count}!
<!-- END BLOCK : row -->
Disclaimer
This software is provided as is without any guarantees or warranty.
Use at OWN risk!
Download
Download (TemplatePower v1.6.2.2a; RAR-archive; 4kB)
Changelog
1.6.2.2a [2010-11-12]:
- bugfix to ensure compatibility to PERL 5.10 and newer
1.6.2.2 [2007-08-28]:
- setVarStartEnd added; not available in PHP TemplatePower
- getVarStartEnd added; not available in PHP TemplatePower
- code cleanup
- full template and code compatibility to 1.6.2
1.6.2.1 [2006-03-21]:
- method assignGlobal added; compatible to PHP TemplatePower 3.0
- method getBlockList added; missing in PHP TemplatePower
- method getVarList added; missing in PHP TemplatePower
- method getVersion added; missing in PHP TemplatePower
- method hasBlock added; missing in PHP TemplatePower
- improved error / warnings handling
- full template and code compatibility to 1.6.2
1.6.2 [2006-02-21]:
- initial release
- straightforward port of PHP module TemplatePower 1.6.2
- full template compatibility to PHP module