thenlabs/nate

一个受Twig启发的模板引擎,充分利用了原生PHP特性。

dev-main 2022-08-26 09:43 UTC

This package is auto-updated.

Last update: 2024-09-26 13:55:52 UTC


README

一个受Twig启发的模板引擎,充分利用了原生PHP特性。

如果你了解 Twig,你就了解Nate。

如果你喜欢这个项目,给我们一个⭐吧。

快速参考。

安装

$ composer require thenlabs/nate dev-main

使用示例。

base.nate.php:

<!DOCTYPE html>
<html lang="<?= $this->lang ?>">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?= $this->title ?></title>

    <?php $this->block('styles') ?>
    <?php $this->endblock() ?>
</head>
<body>
    <?php $this->block('body') ?>
    <?php $this->endblock() ?>

    <?php $this->block('scripts') ?>
    <?php $this->endblock() ?>
</body>
</html>

page.nate.php:

<?php $this->extends('base.nate.php') ?>

<?php $this->block('styles') ?>
    <link rel="stylesheet" href="style.css">
<?php $this->endblock() ?>

<?php $this->block('body') ?>
    <p>This is a paragraph.</p>
<?php $this->endblock() ?>

<?php $this->block('scripts') ?>
    <script src="scripts.js"></script>
<?php $this->endblock() ?>

index.php:

<?php

use ThenLabs\Nate\Template;

$page = new Template(__DIR__.'/page.nate.php');

echo $page->render([
    'lang' => 'en',
    'title' => 'My Title',
]);

输出

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>My Title</title>

    <link rel="stylesheet" href="style.css">
</head>
<body>
    <p>This is a paragraph.</p>

    <script src="scripts.js"></script>
</body>
</html>

开发

克隆此仓库并安装Composer依赖项。

$ composer install

运行测试。

本项目所有测试均使用我们的测试框架PyramidalTests编写,该框架基于PHPUnit

运行测试

$ composer test