Skip to main content

FastPlaz Template Engine

FTE (FastPlaz Template Engine) is a simple template engine written in Pascal for use with FastPlaz. FTE dynamically separates business logic (Pascal code) from presentation logic (view) by allowing special tags to be placed inside an HTML document.

FTE can also cache and apply simple compression to HTML documents.

Because FTE separates business logic from presentation logic, it is easier to split roles between the Developer and the UI Engineer. The UI Engineer can do their work without being directly involved in writing the business logic (Pascal), and vice versa.

Theme​

FTE lets developers freely create various themes for their applications. FTE recommends the following directory and file structure.

├── public_html
│ ├── config
│ ├── files
│ │ └── images
│ ├── modules
│ │ ├── contacts 👈 presenter/view for the Contact module
│ │ └── employees 👈 presenter/view for the Employee module
│ ├── themes
| | ├── ThemeCantik 👈 ThemeCantik theme
| | ├── Dashboard 👈 Dashboard theme
│ │ └── simple 👈 Simple theme
│ │ ├── assets
│ │ ├── plugins
│ │ └── templates
│ └── ztemp

The default theme is selected in the config.json configuration file.

{
"systems" : {

"theme_enable" : true,
"theme" : "Dashboard", 👈 select the theme here

}
}

Example of the HTML master layout in the Basic theme.

<!DOCTYPE html>
<html>
[include file="includes/head"]
<body id="page-top">
[include file="includes/navigation"]
<div id="main">
<div class="container">
<h3>[$Title filter=ucwords]</h3>
</div>
[maincontent]
</div>
[include file="includes/footer"]
</body>
</html>

It looks very simple thanks to Tagging. You can study the details from the example files available in the repository.

Tag​

FTE can process HTML using specific Tag codes.

Construct Tags​

Some of the constructs available in FTE

TagDescription
includeInserts an .html file into the html document
[include file="includes/head"]
foreachLoop for displaying data from a table, array or json
ifConditional
filterApplies a filter to a variable. Currently available: nl2br, uppercase, lowercase, ucwords, moreless, dateformathuman, permalink, multifilter.
example: [$FullName filter=uppercase]
assignAssigns a value to a variable
assigntoAssigns the value of a table field to a variable
blockblock controller

Special Tags​

With several special [tags] such as:

TagDescription
titleDisplays the sitename from config.json
sloganDisplays the slogan from config.json
baseurlDisplays the baseurl from config.json
thisurlCurrent active URL
themeName of the current theme
themepathPath of the current theme
themefullpathFull path, including the BaseURL, of the current theme.
<link rel="stylesheet" href="[themefullpath]/styles/style.css">
datetimeDisplays the date and time, with the default format 'dd MMM YYYY HH:nn:ss'. Use the 'format' parameter to control the output.
Example:[date format="yyyy/dd"]
timeDisplays the time
dateDisplays the date, with the default format 'dd MMM YYYY'. Use the 'format' parameter to control the output.
Example:[date format="yyyy/dd"]
envGets the value of an environment variable,
e.g.: [env key="HTTP_REFERER"]
loadtimeDisplays the application processing time in milliseconds
flashmessagesDisplays Flash Messages, can be used to store error messages
maincontentLocation where each module's main content is displayed

And several featured tags:

TagDescription
recaptchaDisplays ReCaptcha to better secure your forms.
[recaptcha key="your_public_key"]
csrf-tokenCSRF Token as a simple measure to secure forms.
[csrf-token name="optionalModuleName"]
gtGetText, Multi language support.
[gt text="Welcome"]

Usage Examples​

More complete examples of using these tags can be found in the provided examples, especially in the output generated by the Full Package Application wizard.

include​

include inserts an .html file into the document. The file location is relative to the directory of the theme currently in use.

If the Dashboard theme is in use and the tag [include file="includes/head"] is found, the file will resolve to themes/Dashboard/templates/includes/head.html.

<!DOCTYPE html>
<html>
[include file="includes/head"]
<body id="page-top">
[include file="includes/navigation"]
<div id="main">
<div class="container">
<h3>[$Title filter=ucwords]</h3>
</div>
[maincontent]
</div>
[include file="includes/footer"]
</body>
</html>

foreach​

foreach is a loop used to display the contents of data of type table, array or json.

foreach usage format

[foreach from=$VariableName item=row type=table]

html content: [row.nama_field]

[/foreach from=$VariableName]

$VariableName is defined in your controller code.

ThemeUtil.AssignVar['$VariableName'] := @Model.Data;

The following HTML code also shows how to use if inside a foreach block.

<table>
<thead>
<tr><th>&nbsp;</th><th>Name</th><th>Address</th><th></th></tr>
</thead>
<tbody>
[foreach from=$Contacts item=aItem type=table]
[aItem.sex assignto=$JK]
<tr><td>[$index].</td><td>[aItem.first_name] [aItem.last_name]</td><td>[aItem.address]</td><td>[if $JK eq "0"]Laki[else]Perempuan[/if]</td></tr>
[/foreach from=$Contacts]
</tbody>
</table>

Result: Foreach

assignto​

assignto assigns the value of a table field to a variable. This is usually useful when you need a condition on that field.

If the contacts table has a sex field containing 0 or 1, meaning male or female, the html code would look like this:

[foreach from=$Contacts item=aItem type=table]
[aItem.sex assignto=$JK]
<tr><td>[$index].</td><td>[aItem.first_name] [aItem.last_name]</td><td>[aItem.address]</td><td>[if $JK eq "0"]Laki[else]Perempuan[/if]</td></tr>
[/foreach from=$Contacts]

//TODO: Assign