TemplatePower PERL module

21. Februar 2006 · Downloads · andreas · 1 Kommentar
Dieser Beitrag ist in Deutsch 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)
Initialize the template object. The template has to be prepared before use

prepare()
Prepare the template for later use

showUnAssigned([TRUE|FALSE])
Switch if unassigned variables should be returned as empty string (=FALSE) or with their variablename (=TRUE). Default behaviour is FALSE

assign([blockname].variablename, value)
Assign a variable a given value

assignGlobal(variablename, value)
Global assign of a variable. All variables with the name ‘variablename’ will default to ‘value’, but can be overwritten using assign.

assignInclude(templatefile)
Include another template.

gotoBlock(blockname)
Set internal block pointer to block “blockname”

newBlock(blockname)
Add new instance of block “blockname”

getOutputContent()
Return current template as string

printToScreen()
Print current template to STDOUT. Basically the same as “print getOutputContent()”

printVars()
Dump a list of all vars and their values

hasBlock(blockname)
Check if a block named “blockname” exists within the template and returns either TRUE or FALSE

getBlockList()
Return a list of all blocknames defined in the current template

getVarList(blockname)
Return a list of all variablenames defined in the block “blockname”

getVarValue([blockname.]variablename)
Get the current value from a variable. If the variable hasn’t been assigned (yet), undef will be returned.

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

getVarStartEnd()
Return an array containing variable startDelimiter and endDelimiter

getVersion()
Return 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:

mini.pl
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:

mini.tpl
<!-- 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
last update: see Changelog