Template System

From Cloudrexx Development Wiki
Jump to: navigation, search

Note: This documentation refers to version 5 or newer. For older versions of Cloudrexx, please refer to Template System V4.

Cloudrexx uses the PEAR HTML Sigma Template templating system.

Cloudrexx implements a wrapper to the PEAR HTML Sigma Template engine that enables Customizings. You are advised to use the Cloudrexx wrapper (\Cx\Core\Html\Sigma) to make full usage of the Customizings functionality. The wrapper provides the whole function-set as provided by the underlying PEAR HTML Sigma Template engine.

The documentation of PEAR HTML Sigma Template can be found at http://pear.php.net/package/HTML_Template_Sigma/docs.

Placeholder format

Cloudrexx uses a slightly differtent placeholder format than what PEAR HTML Sigma Template uses. In general Cloudrexx uses the following format (notation as regexp):

\[\[[0-9A-Z_]+\]\]

A few examples follow:

[[DATE_YEAR]]
[[PRINT_URL]]
[[CONTACT_ADDRESS]]

For the naming conventions that should be applied to placeholders, please refer to the related article Naming conventions.

Note for developers and webdesigners

It is important to know that the above placeholder format is due to historical reasons and is only used in the view (GUI) of Cloudrexx. Internally (in the database and file system), Cloudrexx uses the placeholder format of PEAR HTML Sigma Template. Which is as follows:

{[0-9A-Za-z_-]+}

Therefore, when interacting directly with the database, please be aware of that the placeholders do not use the same format as the ones that are getting displayed in the backend and Frontend-Editing of Cloudrexx. Same applies to any data that is stored in the file system. Especially if you intent to build a new or modify an existing webdesign-template using your favorite text-editor, remember to use the appropriate format ({[0-9A-Za-z_-]+}) when inserting placeholders.

Interface text - language variables

As Cloudrexx is by design a multilingual system, each interface text is being implemented by a so called "language placeholder" or "language variable". Those placeholders use a special naming convention that is described in the article Text-Variable.

Template Block format

See article Naming Conventions (Template blocks).

Usage

Instead of instantiating a PEAR HTML Sigma Template object, you would simply instantiate a \Cx\Core\Html\Sigma object. You can then use all functions provided by PEAR HTML Sigma Template on the newly created instance of \Cx\Core\Html\Sigma.

// instantiate a new template object
$objTemplate = new \Cx\Core\Html\Sigma('path/to/template/file.html');

// parse a template variable
$objTemplate->setvariable('TXT_FOO', 'bar');

// output parsed template
echo $objTemplate->get();

Front- and Backend Controller

The instantiation of \Cx\Core\Html\Sigma is done automatically by the Component Handler, as well as loading of the requested content page including the associated application template (I.e: View/Template/Default.html). The initialized template object $template can then be used in the parsePage() method of the component controller.

// parse a template variable
$template->setvariable('TXT_FOO', 'bar');

Storage location of template files

Type Location
Frontend View/Template/Frontend/
Backend View/Template/Backend/
Generic View/Template/Generic/