conia/

一个不需要学习新语法的PHP模板引擎

dev-main 2024-01-22 15:36 UTC

This package is auto-updated.

Last update: 2024-09-22 17:34:26 UTC


README

Software License Coverage Status Psalm coverage Psalm level Quality Score

Boiler是一个类似于Plates的PHP 8.1原生模板引擎,它使用PHP本身而不是自定义模板语言。

⚠️ 注意:此模板引擎正在积极开发中,其中一些列出的功能仍然是实验性的,可能会更改。大部分文档尚缺失。

显著差异

  • 它会自动转义字符串和Stringable值。
  • 模板上下文,即模板中所有可用的变量,是全局的。

安装

composer require conia/boiler

快速开始

假设以下目录结构 ...

path
`-- to
    `-- templates
       `-- page.php

... 以及文件 /path/to/templates/page.php 的内容为

<p>ID <?= $id ?></p>

现在创建一个 Engine 实例并渲染模板

use Conia\Boiler\Engine;

$engine = new Engine('/path/to/templates');
$html = $engine->render('page', ['id' => 13]);

assert($html == '<p>ID 13</p>');

运行测试

pest --coverage && \
    psalm --no-cache --show-info=true && \
    phpcs -s -p --ignore=tests/templates src tests

许可证

Boiler在MIT 许可证下发布。

版权 © 2022 ebene fünf GmbH。保留所有权利。