Download the PHP package myerscode/templex without Composer
On this page you can find all versions of the php package myerscode/templex. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download myerscode/templex
More information about myerscode/templex
Files in myerscode/templex
Package templex
Short Description A lightweight, regex based template rendering engine
License MIT
Informations about the package templex
Templex
A lightweight, regex based template rendering engine for PHP
Why this package is helpful?
This package will allow you to define stubs and then hydrate the template using PHP variables.
As the engine uses RegEx it does not rely on using eval
or including and running the code as PHP.
This means that you are able to simply generate new PHP (or any type of text content filled files for that matter) you need.
Install
You can install this package via composer:
Usage
Template Directory
Templates
Templates can be any form of text based files. By default, Templex will look for files with .stub
or .template
file extensions.
Templex uses <{
and }>
as opening and closing anchor tags to find and process Slots
, which can be used to generate
dynamic views from placeholders and logic.
Slots
Slots are the "magic" of Templex. They are the isolated functionality that perform replacement and hydrating actions on a template to create the final rendered output.
The default included slots are:
- IncludeSlot - Includes another templates content
- ControlSlot - Process flow based logic, such as foreach, if statements
- VariableSlot - Replaces single placeholders
Includes
To include another template, in order to create reusable stubs you can simply include it by its template name.
Conditions
Templex can process nested slots, so having nested control conditions are handled in the order they are found.
Conditions can be variables, numbers, booleans or literal strings and can the usual comparison evaluators.
Examples
Loops
Loops will take an array variable to create multiple iterations in your template.
Examples
Variables
Variables are replaced matching anchors are found. They can are passed in at rendering, or created via other slots such as Loops.
Examples
Issues and Contributing
We are very happy to receive pull requests to add functionality or fixes.
Bug reports and feature requests can be submitted on the Github Issue Tracker.
Please read the Myerscode contributing guide for information on our Code of Conduct.
License
The MIT License (MIT). Please see License File for more information.
All versions of templex with dependencies
myerscode/utilities-files Version ^1.0|^2.0
myerscode/utilities-strings Version ^1.0|^2.0