Templates Documentation
Overview
Templates (or views) are HTML files that would be displayed when a specific URL is accessed.
The files are placed in the views/ directory of the project.
File Naming Convention
- View file:
views/contact.html
This would be displayed at the /contact URL - View file:
views/about-us.html
This would be displayed at the /about-us URL
Sub-sections
Subsections are smaller parts of a template that can be included in other templates to avoid repetition and improve organization.
Important: If the path starts with a slash (e.g. /sections/header.html) it would be considered
relative to the top views/ directory. If it doesn't start with a slash (e.g.
sections/header.html) it would be considered relative to the current template file.
Use the following syntax to include files in the main template:
<!--include:sections/common/header.html-->
<!--include:/sections/common/header.html-->
Sub-sections with variables
Sometimes you may want to pass variables to the included template:
<!--include:sections/header.html ["something" => "value"]-->
<!--include:/sections/header.html ["something" => "value"]-->
With that example there would be a variable named something available in the included template
with the value value. You can use it with <!--$something--> in the
sections/header.html
It's important to note that variables passed from the actions would overwrite the variables passed to the included template.
Simple Variables
Use
<!--$variable--> to display simple values:
<h1><!--$title--></h1>
<p>Total items: <!--$count--></p>
Array Access
Access array elements using <!--$array["key"]-->:
<p>Name: <!--$user["name"]--></p>
<p>Email: <!--$user["email"]--></p>
Foreach Loops
Loop through arrays using
<!--foreach()-->:
Simple Loop (Value Only)
<!--foreach($products as $product)-->
<div>
<h3><!--$product[name]--></h3>
<p><!--$product[price]--></p>
</div>
<!--endforeach-->
Loop with Key and Value
<!--foreach($items as $key=>$value)-->
<p>Item #<!--$key-->: <!--$value[name]--></p>
<!--endforeach-->
If Statements
Show or hide content based on conditions:
Positive Condition (if truthy)
<!--if($user_logged_in)-->
<p>Welcome back!</p>
<!--endif-->
Negative Condition (if falsy)
<!--if(!$error)-->
<p>Everything looks good!</p>
<!--endif-->
With Array Access
<!--if($user["premium"])-->
<p>Premium features unlocked!</p>
<!--endif-->
<!--if(!$user["verified"])-->
<p>Please verify your email</p>
<!--endif-->
Truthiness rules:
- Truthy: non-empty strings, numbers (including 0), true, non-empty arrays
- Falsy: empty strings, null, false, undefined variables
Helpers
CSRF Token
Use
<!--csrf--> to render a CSRF token input field in forms:
<form action="/contact">
<!--csrf-->
<input type="email" name="email" />
<input type="submit" value="Submit" />
</form>
Use
<!--csrf_token--> to render just the CSRF token value:
<!--csrf_token-->
Outputs something like 2e6094ee18b504915519fc16f2d605e35e4e167f73e242c273fe70be31911e1c
Flash Messages
Use
<!--flush--> to display all flash messages.
<!--flush--> // Display all flash messages
<!--flush:key--> // Display flash messages of a specific type
Flash messages are wrapped in a div with a type specific class for styling purposes for example:
<div class="flash-success">Success message here</div>
Date Shortcodes
Use
<!--date [format]--> to display the current date/time in various formats.
If no format is provided, the default format Y-m-d H:i:s is used.
<!--date--> // Current date/time in default format
<!--date Y--> // Just the year
<!--date d/m/Y--> // Date in day/month/year format
<!--date F j, Y--> // Full month name, day, year
<!--date l, F j, Y--> // Day of week, full month name, day, year
Examples:
<!--date--> - Returns current date/time in default format: 2026-01-08 14:30:45
<!--date Y--> - Returns just the year: 2026
<!--date d/m/Y--> - Returns date in day/month/year format: 08/01/2026
<!--date F j, Y--> - Returns: January 8, 2026
<!--date l, F j, Y--> - Returns: Wednesday, January 8, 2026
Any valid PHP date format parameter works
Pagination
Use
<!--pagination--> to display a basic pagination navigation.
<!--pagination--> // Pagination with default 10 items per page
<!--pagination 50--> // Pagination with default 10 items per page
The pagination rely on a page parameter in the url e.g.
https://server.com/users?page=2
it would show the records from 11 to 20 if there are more than 10 records.
The action should pass a variable called totalRecords which should contain the total number of
records to paginate. See pagionation example in the Examples section.