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.
- Application::displayTemplate
- Display compiled template
- Application::fetchTemplate
- Return compiled template into a string
- Application::fetchPage
- Return compiled template with declared controller and template variables into a string
- Application::displayPage
- Display compiled template with declared controller and template variables and taking precautionary measures on Clickjacking attacks
Template helper methods
Template helper methods are used for passing special variable to the template.
- Application::setSiteinfo
- Set website information (ex. title, description, keywords)
- Application::setHidden
- Set hidden data
- Application::setHtmlHeader
- Set HTML Header
Template rules
There are several operating notation for template file.
- Variable
- The use of variables in the template
- If
- if, else, else if
- Loop
- loop, foreach
- Include
- include, include head, head, include foot, foot
- Transclude
- transclude, section
- Checked/Selected
- checked, selected
- Options
- Make option tags
- Hidden
- Display hidden tag
- Code
- call, code
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.
$this->page['foo'] = '<p>bar</p>';
{{ $page.foo }} -> <p>bar</p>
{{ $page.foo|noescape }} -> bar
br
Insert HTML line breaks for all newline (\n) found in a string.
$this->page['foo'] = "This is a test text.\n This is a new line text.";
{{ $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.