PHP Classes

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

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

Author

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: 178 Up4 in The Netherlands The Netherlands Up
Innovation award
Innovation award
Nominee: 2x

Example

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

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

clearstatcache();
$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');
echo
'unit 1 ' . $template->tidy('output') . " \n";

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

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

// unit test 4 asp echo's
$template->setVar('pangram', "<%= $embeddedVars".' %>');
$template->parse('output', 'pangram');
echo
'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');
echo
'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');
echo
'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}.'
                          
.'{!endif}');
$template->parse('output', 'pangram');
echo
'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}.'
                          
.'{!endif}');
$template->parse('output', 'pangram');
echo
'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}.'
                          
.'{!endif}');
$template->setVar('printMe2', 'printMe');
$template->parse('output', 'pangram');
echo
'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');
echo
'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');
echo
'unit 10 ' . $template->tidy('output') . " \n";

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

?>


Details

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 (11)  
File Role Description
Files folder imagelicense (3 files)
Files folder imagelogic (1 file)
Accessible without login Plain text file code_of_conduct.md Doc. ethics
Accessible without login Plain text file demo.php Example demo source
Accessible without login Plain text file description.md Doc. explanation
Accessible without login HTML file developer.manual.html Doc. manual
Accessible without login Plain text file sirenade.usage.md 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 (11)  /  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 readme.md Doc. license options

  Files folder image Files (11)  /  logic  
File Role Description
  Accessible without login Plain text file default.inc.php Conf. configuration logic

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
Downloadsirenade-2021-02-13.zip 29KB
Downloadsirenade-2021-02-13.tar.gz
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  
 0%
Total:40
This week:0
All time:10,888
This week:560Up