The Template Engine

The template engine in BitOwl Application Suit allows for a safe subset of scripting capabilities to be available to the template author. It is designed to allow the template information to be completely separated from the scripts themselves. The syntax of the templates is not particularly based on any previous langauge.

To add small pieces of scripts you must enclose the template code into HTML comments like so:

<!-- // Code goes here -->

As seen above, the only form of commenting available are single line comments. These are formed by prepending // to the line in which you do not wish to be included in the final output.

Commands can be broken by a semicolon or simply by a new line. Do note that the opening and closing statements are considered commands and must be separated by a semicolon if they are used in the same line.

In some cases it may be needed to have a block of code be outputted without being parsed by the template engine. Using <!--- as the opening statement means that anything inside should be printed as is.

<!--- Stuff that needs to be printed without being parsed by the template engine can go here. -->

Variables

Variables are simply identifiers that are not reserved by the language itself. They access an array in the PHP code with each dot separated identifier being an index in the array. For example somevar.element would go to $template_engine->variables['somevar']['element'].

In addition certain keywords in the first element are reserved to access other variables. language.STRING will access the specified string from the currently in use language file. get.variable will access the global $_GET['variable']. And lastly post.variable will get the value from $_POST['variable'].

Some times it is needed to make an element the value of another variable. To do this enclose the variable in parenthesis. For example somvar.(i) would translate to $template_engine->variables['somevar'][$template_engine->variables['i']]. This is particularly useful when a for loop is used.

Variables can be printed from outside of a template block. To do this encode the variable in braces ({ and }). For example {variable}.

Functions

The following functions are available for use in templates.

Conditionals

A limited set of conditional statements are available. These must be terminated with the end keyword. See the following example for reference.

<-- if(variable) print(language.YES); end; // The semicolons are optional -->

Boolean Expressions

The template engine allows a limit set of operators to be used in boolean expressions (if statments). These operators include <, >, /, *, +, -, %, !=, ==, <=, >=, or, ||, &&, and, xor, ===, !==, isset(variable), empty(variable), is_numeric(variable), is_string(variable), is_array(variable), is_null(variable), and count(variable). Integers, strings, and variables can be used in the comparisons.

Using the Template Engine from PHP

The template engine is initialized in index.php and init.php. For parts of the main control panel you can access it from $template_engine. For parts on the end-user's website the template engine is at $_bitowl['templates'].

To set the value of a variable in a template simply set the proper array index in the variables property in the template engine object. For example: $template_engine->variables['myvar'] = 'test'; would set myvar to the string 'test'.

To display a template from the control panel you may use the template(str $template) function the the template engine object, but from end-user scripts it is preferable to use the showTemplate(str $template, bool $fullpath=false) function (this is a global function not part of the template engine). This function loads the proper template based on what was selected in the system cp.

Standard Template Variables

Init.php (Globals)

comment.html

journalist_article.html

gallery_image.html

gallery_layout.html

paginate.html