Skip to main content

About Template

About Template

Fegg is equipped with its own template engine where you can separate application code (PHP Code) and display (HTML/CSS). Fegg uses the {{}} tag for your application code in the template file. It runs a method that compile templates from Controller class.

Template files are save under the code/template/ directory with name format of template_name.tpl.

Display methods

Display methods call the template file from Controller class.

Below are the display methods in Fegg but it is recommended to use only the displayPage method to avoid Clickjacking attacks.

Template helper methods

Template helper methods are used for passing special variable to the template.

Template rules

There are several operating notation for template file.

Modifiers

How to use modifiers

You can modify the returned values of your variable in your application code in template using modifiers.

Modifiers are separated from the variable using pipe symbol ( | ) and may have an optional argument separated by colon symbol ( : ). Multiple modifiers can be chained, it modifies the variable from left to right. Thus, the output of the first filtering is applied to the next filtering.

{{ $var|noescape|function:param }}

noescape

Fegg is automatically escaping character values. If you don’t want a escaping value, you can use the noescape modifier.

Controller
$this->page['foo'] = '<p>bar</p>';
Template
{{ $page.foo }} -> <p>bar</p>
{{ $page.foo|noescape }} -> bar

br

Insert HTML line breaks for all newline (\n) found in a string.

Controller
$this->page['foo'] = "This is a test text.\n This is a new line text.";
Template
{{ $page.foo }} -> This is a test text. This is a new line text.
{{ $page.foo|br }} -> This is a test text.
This is a new line text.