Download the PHP package sy/template without Composer
On this page you can find all versions of the php package sy/template. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package template
sy/template
A simple template engine for PHP
Installation
Install the latest version with
Basic Usage
Variables
The template file mytemplate.tpl content:
The output result:
Blocks
The template file mytemplate.tpl content:
The output result:
Isolated variables for a block
The template file mytemplate.tpl content:
The output result:
Advanced Usage
Naming Conventions
Starting at version 3, slot and block names are more restrictive. They must:
- Use only uppercase letters (
A-Z), digits (0-9), and underscores (_). - Contain at least one uppercase letter (they cannot be composed solely of digits or underscores).
- Start with an uppercase letter or an underscore followed by an uppercase letter.
Valid names: NAME, MY_BLOCK, BLOCK_1, _NAME.
Invalid names: name, 123, _123, MY-BLOCK.
Note: Slots wrapped in double or single quotes (e.g., {"Hello"}) are not subject to these naming restrictions.
ELSE block
You can set a default ouput for a block when this one is not set using the ELSE block:
The template file mytemplate.tpl content:
The output result:
Slot advanced syntax
1. Simple or double quotes around slot name
You can use double or simple quotes around the slot name:
If these slots are not set, the output will be the string inside of the simple or double quotes:
2. Slot default value
You can set a default value for a slot when this one is not set using a slash caracter after the slot name:
If the slot is not set, the output will be:
Slot default behavior
Version 1
The slot default behavior changed on the version 2. Before, on the version 1, an unset slot is cleared on output:
If the slot is not set, the output will be:
Version 2
Starting at version 2:
If the slot is not set, the output will be:
How to clear the slot automatically
You can use the "Slot default value" feature to achieve that. The slot will be replaced by the string after the slash, so if you put an emtpy string after the slash, the slot will be replaced by an empty string:
If the slot is not set, the output will be: