corviz/crow

PHP 模板引擎

v2.1 2023-10-26 17:59 UTC

This package is auto-updated.

Last update: 2024-08-26 19:50:30 UTC


README

又一个 PHP 模板引擎

特性

  • 易于扩展 - 您可以创建新方法来满足您的需求
  • 广泛的语法(类似于 Blade)
  • 框架无关 - 您可以在任何项目中使用它
  • 易于配置 - 简直只需要2条命令即可完成基本配置(如果您不使用组件/自定义标签,则为1条命令)
  • MIT 许可证。商业和非商业使用免费

使用 composer 安装

composer require corviz/crow

快速入门

在主脚本中

use Corviz\Crow\Crow;

Crow::setDefaultPath('/path/to/templates/folder');
Crow::setComponentsNamespace('MyComponents'); //Required only if you will use components/custom tags

Crow::render('index');

在 /path/to/templates/folder/index.crow.php

<!DOCTYPE html>
<html>
    <head>
        <title>Index</title>
    </head>
    <body>
        {{ 'Hello world' }}
    </body>
</html>

基本循环示例

在主脚本中

$todoList = ['Work', 'Clean house', 'Relax'];

Crow::render('template', ['todoList' => $todoList]);

模板文件

<h1>Todo:</h1>
<ul>
    @foreach($todoList as $task)
        <li>{{ $task }}</li>
    @endforeach
</ul>

致谢

喜欢它吗?

访问 https://corviz.github.io/crow/ 以获取文档/示例