The implementation of the Stupid Template Engine.
stupid_template_engine.php | The implementation of the Stupid Template Engine. |
License | This file is licensed under the MIT/X11 License. |
ste | Everything in this file is in this namespace. |
Functions | |
precompile | Precompiling STE T/PL templates. |
parse | Parsing a STE T/PL template. |
transcompile | Transcompiles an abstract syntax tree to PHP. |
Constants | |
Template modes | |
StorageAccess | An interface. |
Functions | |
load | Loading a template. |
save | Saves a template. |
FilesystemStorageAccess | The default StorageAccess implementation for loading / saving templates into a directory structure. |
Functions | |
__construct | |
STECore | The Core of STE |
Variables | |
Public variables | |
Functions | |
__construct | |
register_tag | Register a custom tag. |
call_tag | Calling a custom tag (builtin ones can not be called) |
exectemplate | Executes a template and returns the result. |
get_var_reference | Get a reference to a template variable using a variable name. |
set_var_by_name | Set a template variable by its name. |
get_var_by_name | Get a template variable by its name. |
load | Load a template and return its result (blocks not included, use exectemplate for this). |
evalbool | Test, if a text represents false (an empty / only whitespace text) or true (everything else). |
Everything in this file is in this namespace.
Functions | |
precompile | Precompiling STE T/PL templates. |
parse | Parsing a STE T/PL template. |
transcompile | Transcompiles an abstract syntax tree to PHP. |
Constants | |
Template modes |
function parse( $code, $tpl )
Parsing a STE T/PL template. You only need this function, if you want to manually transcompile a template.
$code | The STE T/PL code. |
$tpl | The name of the template. |
An abstract syntax tree, which can be used with transcompile.
function transcompile( $ast ) /* Transcompile and add some boilerplate code. */
Transcompiles an abstract syntax tree to PHP. You only need this function, if you want to manually transcompile a template.
$ast | The abstract syntax tree to transcompile. |
PHP code. The PHP code is an anonymous function expecting a STECore instance as its parameter and returns a string (everything that was not pached into a section).
public function load( $tpl, & $mode )
Loading a template.
$tpl | The name of the template. |
&$mode | Which mode is preferred? One of the <Template modes>. If <MODE_SOURCE>, the raw sourcecode is expected, if <MODE_TRANSCOMPILED> the transcompiled template as a callable function (expecting an STECore instance as first parameter) is expected. If the transcompiled version is not available or older than the source, you can set this parameter to <MODE_SOURCE> and return the source. |
Either the sourcecode or a callable function (first, and only parameter: an STECore instance).
The default StorageAccess implementation for loading / saving templates into a directory structure.
public function __construct( $src, $transc )
$src | The directory with the sources (Writing permissions are not mandatory, because STE does not save template sources). |
$transc | The directory with the transcompiled templates (the PHP instance / the HTTP Server needs writing permissions to this directory). |
The Core of STE
Variables | |
Public variables | |
Functions | |
__construct | |
register_tag | Register a custom tag. |
call_tag | Calling a custom tag (builtin ones can not be called) |
exectemplate | Executes a template and returns the result. |
get_var_reference | Get a reference to a template variable using a variable name. |
set_var_by_name | Set a template variable by its name. |
get_var_by_name | Get a template variable by its name. |
load | Load a template and return its result (blocks not included, use exectemplate for this). |
evalbool | Test, if a text represents false (an empty / only whitespace text) or true (everything else). |
public function __construct( $storage_access )
$storage_access | An Instance of a StorageAccess implementation. |
public function register_tag( $name, $callback )
Register a custom tag.
$name | The name of the tag. |
$callback | A callable function (This must tage three parameters: The STECore instance, an associative array of parameters, and a function representing the tags content(This expects the STECore instance as its only parameter and returns its text result, i.e to get the text, you neeed to call this function with the STECore instance as a parameter)). |
public function call_tag( $name, $params, $sub )
Calling a custom tag (builtin ones can not be called)
$name | The Tag’s name |
$params | Associative array of parameters |
$sub | A callable function (expecting an STECore instance as it’s parameter) that represents the tag’s content. |
The output of the tag.
public function exectemplate( $tpl )
Executes a template and returns the result. The huge difference to load is that this function will also output all blocks.
$tpl | The name of the template to execute. |
The output of the template.
public function &get_var_reference( $name, $create_if_not_exist )
Get a reference to a template variable using a variable name. This can be used,if your custom tag takes a variable name as a parameter.
$name | The variables name. |
$create_if_not_exist | Should the variable be created, if it does not exist? Otherwise NULL will be returned, if the variable does not exist. |
A Reference to the variable.
public function load( $tpl, $quiet = False )
Load a template and return its result (blocks not included, use exectemplate for this).
$tpl | The name of the template to be loaded. |
$quiet | If true, do not output anything and do notmodify the blocks. This can be useful to load custom tags that are programmed in STE T/PL. Default: false. |
The result of the template (if $quiet == false).
Precompiling STE T/PL templates.
function precompile( $code )
Parsing a STE T/PL template.
function parse( $code, $tpl )
Transcompiles an abstract syntax tree to PHP.
function transcompile( $ast ) /* Transcompile and add some boilerplate code. */
Loading a template.
public function load( $tpl, & $mode )
Saves a template.
public function save( $tpl, $data, $mode )
public function __construct( $src, $transc )
public function __construct( $storage_access )
Register a custom tag.
public function register_tag( $name, $callback )
Calling a custom tag (builtin ones can not be called)
public function call_tag( $name, $params, $sub )
Executes a template and returns the result.
public function exectemplate( $tpl )
Get a reference to a template variable using a variable name.
public function &get_var_reference( $name, $create_if_not_exist )
Set a template variable by its name.
public function set_var_by_name( $name, $val )
Get a template variable by its name.
public function get_var_by_name( $name )
Load a template and return its result (blocks not included, use exectemplate for this).
public function load( $tpl, $quiet = False )
Test, if a text represents false (an empty / only whitespace text) or true (everything else).
public function evalbool( $txt )