承接 alexoliverwd/brace 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

alexoliverwd/brace

Composer 安装命令:

composer require alexoliverwd/brace

包简介

A simple template language written in PHP

README 文档

README

PHPUnit Latest Stable Version License

Brace Logo

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:

  1. Variables
  2. Filters
  3. Conditional Statements
  4. Iterators
  5. Loops
  6. Function Hooks
  7. Shortcodes
  8. Includes

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 || "&pound;" }}{{ 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> &pound;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> &pound;16.00 </span>
                    <p>This is another product description</p>

                    <button id="1156">Add to basket</button>
                </li>
            </ul>
        </main>
    </body>
</html>

Next Steps

Getting Started

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 我们能提供哪些服务?
定制开发 / 二次开发

基于 alexoliverwd/brace 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 3.88k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 17
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-09-16