Download the PHP package brainlight/brainlight-php without Composer
On this page you can find all versions of the php package brainlight/brainlight-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download brainlight/brainlight-php
More information about brainlight/brainlight-php
Files in brainlight/brainlight-php
Package brainlight-php
Short Description Brainlight template engine for PHP.
License MIT
Homepage https://github.com/GiromettaMarco/brainlight-php
Informations about the package brainlight-php
Brainlight PHP
Brainlight is a lightweight templating system with minimal logic pattern.
This is a PHP implementation of the Brainlight paradigm.
- Requirements
- Installation
- Usage
- Additional logic
- Options
- License
Requirements
- PHP >= 8.1
- Composer
Installation
Require Brainlight Php package in your composer project using the following command:
Usage
Create a new Brainlight Engine instance:
Then render any Brainlight template:
Make reference to the Brainlight documentation for templates syntax.
Additional logic
Brainlight PHP supports templates with additional logic by making use of the class and namespaces.
First consider adding a namespace root in your engine configuration:
Then create a new logic class by extending :
This way, while rendering and class will be loaded.
In addition, the template name inside these tags will be converted to a namespace. So will become .
A Logic class must implement the method:
The purpose of this function is to modify the arguments passed to the template. Such arguments are collected inside the associative array.
It is possible to set mandatory arguments using the array property and mandatory slots using the array property:
It is also possible to change the default template associated with a logic class by setting its property:
To render a template with additional logic directly from a PHP script, use the third parameter of the function:
Options
The Engine constructor supports the following options:
cacheDir
Type: string
Absolute path where cached templates will be stored.
This field is mandatory.
templatesDir
Type: mixed
Absolute path to the directory containing templates. It also accepts an array of paths.
If is provided, the method will accept a fully qualified filename instead of a template name.
Example:
Default value:
partialsDir
Type: mixed
Absolute path to the directory containing partial templates for inclusions and extensions. It also accepts an array of paths.
If is provided, the template engine will consider the template name of inclusion tags as a fully qualified filename instead of a template name.
If is provided, partial templates will be resolved according to the same rule set with .
Default value:
logicNamespace
Type: string|bool
Namespace root used to resolve additional logic classes.
Default value:
extension
Type: string
The Brainlight template file extension.
Default value:
Escaping options
The following options (with default value) are applied to any escape operation performed with the PHP function htmlspecialchars:
License
Brainlight PHP is open-sourced software licensed under the MIT license