PHP Classes


Recommend this page to a friend!
  Classes of wim niemans   Sirenade PHP Template Compiler   Download  
Role: Documentation
Content type: text/markdown
Description: api docs
Class: Sirenade PHP Template Compiler
Compile templates to PHP and caches the results
Author: By
Last change: removed doubled text
Date: 3 years ago
Size: 3,096 bytes


Class file image Download


A lot of template engines just replace markers in a text by other text. The concept of boilerplate is their base feature. SIRENADE is built on SIREN, that does the intelligent replacing. Please refer to the package SIREN for basic syntax of markers and variables. SIRENADE adds logic to the replacement algorithms, and caches files and blocks. But above all, SIRENADE will compile the input template into native PHP code and invokes a secure eval to produce the content. Two base classes are available: Template to compile the template text and Stencil to cache the compiled result. This means that Stencil invokes Template whenever the input template text is not yet cached, or retrieves the cached result. The effect is that a first run of Stencil is always slower than all other following runs.


Benefits of SIRENADE include:

  • It is very easy: no kowledge of programming necessary.
  • It is very fast: it beats loading of files easily.
  • It supports simple logic with a simple syntax, and supports advanced logic to contain embedded (recursive) variables.
  • It supports PHP tags and ASP tags.

Logic Syntax Conventions

SIRENADE supports:

  • if - then - else constructs,
  • while - and foreach loops with incrementing / decrementing loop variables,
  • break and continue,
  • set - and unset variables,
  • and allows mixing with PHP native code and ASP coding styles.

Like SIREN, the brackets convention is used for simple and advanced logic. SIRENADE extends this with a XML like convention for native PHP tags and ASP coding syles.

{!<simple logic>} or {!<simple logic>!} {!!<advanced logic> !!} {# <comment> #} or <!-- <comment> --> {$ <formatted global variable> $} {= <object access> =}

<?php <native PHP code> ?> <% <ASP logic> %> <?= <scalar> ?> or <%= <scalar> %>


Simple Logic

{!if myVar} myVar exists {!else) myVar is an orphan {!endif) {!if {myVar}} myVar has value {myVar} and exists {!else) myVar or {myVar} is an orphan {!endif)

{!while myVar} the value of myVar is {myVar}. {!unset myVar} {!endwhile} {!while myVar} the value of myVar is {myVar}. {!break} {!endwhile}

{!loop 5} five times. {!endloop) {{!loop myVar} {myVar} times. {!endloop)

Advanced Logic

{!if myVar == 'abc' } myVar equals 'abc' {!else) myVar does not equal 'abc' {!endif) {!if {myVar} == 'abc' } the value {myVar} of myVar equals 'abc' {!else) the value of myVar {myVar} does not equal 'abc' {!endif)

ASP Logic

<% for language in languages%> <%= language %> <% endfor %> <% for language in {languages} %> <%= language %> <% endfor %> <% for {language} in {languages} %> <%= {language} %> <% endfor %>

Native Code

PHP native code



Extended methods

Formatting a Global Variable

Object Access