alexoliverwd/brace
Composer 安装命令:
composer require alexoliverwd/brace
包简介
A simple template language written in PHP
关键字:
README 文档
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>
Next Steps
alexoliverwd/brace 适用场景与选型建议
alexoliverwd/brace 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.88k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2020 年 09 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「template」 「html」 「handlebars」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 alexoliverwd/brace 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 alexoliverwd/brace 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 alexoliverwd/brace 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Handlebars processor for php
Texy converts plain text in easy to read Texy syntax into structurally valid (X)HTML. It supports adding of images, links, nested lists, tables and has full support for CSS. Texy supports hyphenation of long words (which reflects language rules), clickable emails and URL (emails are obfuscated again
This Symfony bundle provides integration for the handlebars template engine.
Parse Handlebars templates to a spec-compliant AST with PHP.
HTML and form generation
Simple ASCII output of array data
统计信息
- 总下载量: 3.88k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 17
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-09-16