Template System

From Cloudrexx Development Wiki
Jump to: navigation, search

Contrexx uses the PEAR HTML Sigma Template templating system.

Contrexx implements (since version 3) a wrapper to the PEAR HTML Sigma Template engine that enables Customizings. You are advised to use the Contrexx 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

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


A few examples follow:


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 Contrexx. Internally (in the database and file system), Contrexx uses the placeholder format of PEAR HTML Sigma Template. Which is as follows:


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 Contrexx. 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 Contrexx 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).


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. <highlightsyntax>// 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();</highlightsyntax>

Front- and Backend Controller

As of version 3.1, the instantiation of \Cx\Core\Html\Sigma is already done by the Component Handler, as well as loading of the requested content page or appropriate backend template (from the template repository of the loaded component. I.e: View/Template/Default.html). The initialized template object $template can then be used in the parsePage() method of the component controller.

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

Storage location of template files

This section is a stub and must be completed!