PHP Classes

Sirenade PHP Template Compiler: Compile templates to PHP and caches the results

Recommend this page to a friend!
  Info   View files Example   View files View files (11)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 40 All time: 10,855 This week: 560Up
Version License PHP version Categories
sirenade 1.1Custom (specified...7Cache, Templates, Code Generation, PHP 7


This package can compile templates to PHP and caches the results.

It extends the SIREN class to implement a template processing engine that can process templates defined as strings.

The engine generates a PHP script that will output the template processing results when it is executed.

The results of the template compilation are stored in cache files to reduce the time to process the same template again.

The template engine can process templates that may have marks that determine if a section is processed according to condition. It can also iterate over a section to process it in a loop.

Picture of wim niemans
  Performance   Level  
Name: wim niemans <contact>
Classes: 6 packages by
Country: The Netherlands The Netherlands
Age: ???
All time rank: 345989 in The Netherlands The Netherlands
Week rank: 286 Up7 in The Netherlands The Netherlands Up
Innovation award
Innovation award
Nominee: 2x


 * This file is an example of an application with Templet class.
 * Distribution is intended for education / studying purposes only.
 * Copyright [2021] [Wim Niemans <>]

include '../Template.class.php';

 * @author wim niemans, Rotterdam, Bonn
 * @license EUPL

$template = new Template(); // default: keepOrphans

$template->setVar('speed', 'quick');
$template->setVar('color', 'brown');
$template->setVar('action', 'jumps');
$template->setVar('pet', 'dog');
$template->setVar('printMe', true); // variable used in logic features

$time = microtime(true);

$embeddedVars = '"The ".{speed}." ".{color}." fox ".{action}." over the lazy ".{pet}."."';
// unit test 1 php native
$template->setVar('pangram', "<?php echo $embeddedVars ".' ?'.'>');
$template->parse('output', 'pangram');
'unit 1 ' . $template->tidy('output') . " \n";

// unit test 2 php echo native
$template->setVar('pangram', "<?= $embeddedVars".' ?'.'>');
$template->parse('output', 'pangram');
'unit 2 ' . $template->tidy('output') . " \n";

// unit test 3 asp tags
$template->setVar('pangram', "<% echo $embeddedVars".' %>');
$template->parse('output', 'pangram');
'unit 3 ' . $template->tidy('output') . " \n";

// unit test 4 asp echo's
$template->setVar('pangram', "<%= $embeddedVars".' %>');
$template->parse('output', 'pangram');
'unit 4 ' . $template->tidy('output') . " \n";

// unit test 5 html comment
$template->setVar('pangram', '<!-- The {speed} {color} fox {action} over the lazy {pet}. -->');
$template->parse('output', 'pangram');
'unit 5 ' . $template->tidy('output') . " \n";

// unit test 6 native comment
$template->setVar('pangram', '{# The {speed} {color} fox {action} over the lazy {pet}. #}');
$template->parse('output', 'pangram');
'unit 6 ' . $template->tidy('output') . " \n";

// unit test 7 advanced logic
$template->setVar('pangram', '{!!if {printMe} == true !!}'
.'The {speed} {color} fox {action} over the lazy {pet}.'
$template->parse('output', 'pangram');
'unit 7 ' . $template->tidy('output') . " \n";

// unit test 8 simple logic
$template->setVar('pangram', '{!if printMe}'
.'The {speed} {color} fox {action} over the lazy {pet}.'
$template->parse('output', 'pangram');
'unit 8 ' . $template->tidy('output') . " \n";

// unit test 8A simple logic
$template->setVar('pangram', '{!if {printMe2}}'
.'The {speed} {color} fox {action} over the lazy {pet}.'
$template->setVar('printMe2', 'printMe');
$template->parse('output', 'pangram');
'unit 8A ' . $template->tidy('output') . " \n";

// unit test 9 global var
$template->setVar('pangram', '{$globalMe {speed},{color},{action},{pet} }');
$globalMe = 'The %s %s fox %s over the lazy %s.';
$template->parse('output', 'pangram');
'unit 9 ' . $template->tidy('output') . " \n";

// unit test 10 object access
$template->setVar('pangram', '{@template getVar output @}');
$template->setVar('template', $template);
$template->parse('output', 'pangram');
'unit 10 ' . $template->tidy('output') . " \n";

$elapsed = microtime(true) - $time;
"\n elapsed $elapsed \n";



SIRENADE is a base PHP library that compiles the template text into native PHP and caches the compiled output. It is using the package SIREN for basic functions.

SIREN has a simple, sufficient API, performs recursive replacement, and uses an intuitive syntax.  

syntax: {[$|?]var} where var  is [text]{var}[text]  
                   where text is '-._[\w\d\]'

SIRENADE allows for embedding native PHP in the template text and features a nice set of logic directives:

if - elseif - else  
while and loop with count  
for - and foreach struvtures  
increment / decrement counts  
break and continue  
global strings thru sprintf  
set and unset variables (i.e. template variables)
<?php .... ?>  
(experimental) ASP logic

Like SIREN, it features recursion in an intuitive way and extends SIREN's usage with

syntax {!<simple logic>!}
       {!!<advanced logic>!!}
       {# <comments> #}
       <!-- <comments> -->
       <?php <custom native PHP> ?>
       <?= <scalar> ?>
       {$<global string variable> <parameter>}
       <% <ASP logic> %>
       <%= <scalar> %>

SIRENADE has all logic expansions and their syntax externally defined as anonymous functions, and allows for simple custom adjustments, or even complete customised additions. See the directory './logic'.

SIRENADE can cache files and blocks on demand, leaving the SIREN recursion for run time expansion. SIRENADE comes with an extensive set of configurable options.

SIRENADE is very fast, not depending on the number of markers, nor the volume of logic.

More documentation: full readme, api docs, logic, license.

  Files folder image Files  
File Role Description
Files folder imagelicense (3 files)
Files folder imagelogic (1 file)
Accessible without login Plain text file Doc. ethics
Accessible without login Plain text file demo.php Example demo source
Accessible without login Plain text file Doc. explanation
Accessible without login HTML file developer.manual.html Doc. manual
Accessible without login Plain text file Doc. api docs
Plain text file Stencil.class.php Class caching class
Plain text file Template.class.php Class compiling class

  Files folder image Files  /  license  
File Role Description
  Accessible without login Plain text file CDDL_1.LICENSE Lic. CDDL license
  Accessible without login Plain text file EUPL-1.2.LICENSE Lic. EUPL license
  Accessible without login Plain text file Doc. license options

  Files folder image Files  /  logic  
File Role Description
  Accessible without login Plain text file Conf. configuration logic 29KB
Install with ComposerInstall with Composer
Needed packages  
Class DownloadWhy it is needed Dependency
SIREN PHP Templating Library Download .zip .tar.gz Parsing and Substituting is left to Siren or any other package that supports it using the same method names. Required
 Version Control Unique User Downloads Download Rankings  
This week:0
All time:10,855
This week:560Up