alexoliverwd / brace
A simple template language written in PHP
Requires
- php: >=8.4.1
Requires (Dev)
- captainhook/captainhook-phar: ^5.29
- laravel/pint: ^1.29
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^13.1
- rector/rector: ^2.4
- dev-main
- v1.4.1
- v1.4.0
- v1.3.1
- v1.3.0
- v1.2.1
- v1.2.0
- v1.1.4
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.27
- v1.0.26
- v1.0.25
- v1.0.24
- v1.0.23
- v1.0.22
- v1.0.21
- v1.0.20
- v1.0.19
- v1.0.19a
- v1.0.18
- v1.0.18b
- v1.0.17
- v1.0.16
- v1.0.15
- v1.0.14
- v1.0.13
- v1.0.12
- v1.0.11
- v1.0.10
- v1.0.9
- v1.0.8
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- dev-development
- dev-merge
- dev-copilot/add-documentation-with-code-examples
This package is auto-updated.
Last update: 2026-05-21 14:40:45 UTC
README
Brace
Brace is a lightweight templating syntax for PHP that uses a familiar {{ double-brace }} syntax. It shares similarities with popular templating engines such as Mustache, Twig, Smarty, and Latte.
Designed to be simple and easy to adopt, Brace focuses on a low learning curve while remaining flexible enough for most templating needs. It provides essential functionality out of the box without requiring additional dependencies.
Key Features:
Syntax
By default, Brace loads .tpl files from the current directory. The following example loads multiple templates, document-header.tpl, template.tpl, and document-footer.tpl, and outputs them as a single HTML file.
<?php use Brace\Parser; $brace = new Parser(); // Register filters $brace->registerFilter('int', fn($content) => (int) $content); $brace->registerFilter('decimal', fn($number) => number_format($number, 2)); $brace->registerFilter('uppercase', fn($content) => strtoupper($content)); $brace->registerFilter('titlecase', fn($content) => ucwords($content)); $brace->registerFilter('striptags', fn($content) => strip_tags($content)); // Register shortcode $brace->regShortcode('add_to_basket_button', fn($attrs) => sprintf( '<button id="%d">Add to basket</button>', $attrs['product_id'], )); $brace->parse('template, document-footer', [ 'name' => 'Jane Doe', 'products' => [ 0 => [ 'id' => 1154, 'price' => 22.66, 'title' => 'Product Number One', 'description' => 'This is a product description', ], 1 => [ 'id' => 1156, 'price' => 16, 'title' => 'Product Number Two', 'description' => 'This is another product description', ], ], ]);
Template:
<!-- Simple HTML template --> [@include document-header] <main> <p>Hello World. My name is {{ name|titlecase || "John Doe" }}</p> <h1>Product List:</h1> {{ if products }} <p>Showing {{ COUNT(products) }} item(s)</p> <ul> {{ each products as product }} <li> <span>{{ product->title|uppercase }}</span> <span> {{ product->currancy_symbol || "£" }}{{ product->price|decimal }} </span> <p>{{ product->description|striptags }}</p> [add_to_basket_button product_id="{{ product->id|int }}"] </li> {{ end }} </ul> {{ else }} <p>No products to list</p> {{ end }} </main>
Result:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Brace Examples</title> </head> <body> <main> <p>Hello World. My name is Jane Doe</p> <h1>Product List:</h1> <p>Showing 2 item(s)</p> <ul> <li> <span>PRODUCT NUMBER ONE</span> <span> £22.66 </span> <p>This is a product description</p> <button id="1154">Add to basket</button> </li> <li> <span>PRODUCT NUMBER TWO</span> <span> £16.00 </span> <p>This is another product description</p> <button id="1156">Add to basket</button> </li> </ul> </main> </body> </html>