TemplatePower PERL module

Dieser Artikel ist in Ihrer Sprache nicht verfügbar.

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)

initializes the template object. The template has to be prepared before use.

prepare ()

prepares the template for later use.

showUnAssigned ([TRUE|FALSE])

switches if unassigned variables should be returned as empty string (=FALSE) or with their variablename (=TRUE). Default behaviour is FALSE

assign ([blockname].variablename, value)

assigns a variable a given value

assignGlobal (variablename, value)

does a global assign of a variable. All variables with the name ‚variablename‘ will default to ‚value‘, but can be overwritten using assign.

assignInclude (templatefile)

includes another template.

gotoBlock (blockname)

sets internal block pointer to block ‚blockname‘

newBlock (blockname)

adds a new instance of block ‚blockname‘

getOutputContent ()

returns the content of the current template as string

printToScreen ()

prints the content of the current template to STDOUT. Basically the same as print getOutputContent()

printVars ()

dumps a list of all vars and their values

hasBlock (blockname)

checks if a block named blockname exists within the template and returns either TRUE or FALSE

getBlockList ()

will return a list containing all blocknames defined in the current template.

getVarList (blockname)

will return a list containing all variablenames defined in the block ‚blockname‘.

getVarValue ([blockname.]variablename)

will get the current value from a variable. If the variable hasn’t been assigned (yet), undef will be returned.

setVarStartEnd (startDelimiter, endDelimiter)

changes variable startDelimiter and endDelimiter to the given values
setVarStartEnd has to be called BEFORE preparing the template, otherwise it will have no effect!

getVarStartEnd ()

returns an array containing variable startDelimiter and endDelimiter

getVersion ()

returns the current TemplatePower version

TemplatePower Templates

Variables

{variablename}

Variable names may consist of characters and digits.

Blocks

<!– START BLOCK : blockname –>
whatever should be in the block
<!– END BLOCK : blockname –>

Blocks can be nested.

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!

Changelist

1.6.2.2a [12.11.2010]

  • bugfix to ensure compatibility to PERL 5.10 and newer

1.6.2.2 [28.08.2007]

  • 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 [21.03.2006]

  • 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 [21.02.2006]

  • initial release
  • straightforward port of PHP module TemplatePower 1.6.2
  • full template compatibility to PHP module

Download

templatepower (RAR-Archive, 5kb)

Kommentar schreiben