anovsiradj / cutter
灵活的模板库
4.0.0
2024-06-10 01:25 UTC
Requires
- php: >=5.6
Requires (Dev)
- symfony/var-dumper: ~3 || @stable
README
灵活的模板库。灵感来自 Blade (Laravel) 和 Twig (Symfony)。
在 PHP 5.6
,~7
和 ~8
上进行了测试。
安装
composer require anovsiradj/cutter
示例
/index.php
require 'Cutter.php'; // directly or composer $cutter = new anovsiradj\Cutter; $cutter->set('layout','/layouts/main'); $cutter->data('page_title', 'My Posts'); // set variable $cutter->view( '/pages/home', ['date_today' => date('Y-m-d')], // set variable(s) );
/layouts/main.php
使用 section()
来定义部分
<!DOCTYPE html> <html> <head> <title><?= $page_title ?></title> </head> <body> <div> <?php $cutter->section('content') ?> <div> <?php $cutter->section('script') ?> </body> </html>
/pages/home.php
使用 begin()
和 end()
来输出缓冲区部分
<?php $this->begin('content') ?> <ul> <li>Post title 1</li> <li>Post title 2</li> <li>Post title 3</li> </ul> <?php $this->end() ?> <?php $this->begin('script') ?> <script>alert('date today is <?php echo $date_today ?>')</script> <?php $this->end() ?>
更多信息,请查看 /example/
。
参考
类方法
get( $key ) : void; set( $key, mixed $val ) : void; data( mixed $any [, mixed $val] ): mixed; load( $file [, bool $isob = false] ): void; view( mixed $name [, array $data = [] [, bool $render = true ] ] ) : void; render( [array $data = [] ] ) : void; section( $name ) : bool; begin( $name ) : void; end(): void
开发
TODO
- 单文件库 / Phar?
- 继承
动态路径动态视图
所有建议都受欢迎。谢谢。