anovsiradj / cutter
Flexible Template Library
4.0.0
2024-06-10 01:25 UTC
Requires
- php: >=5.6
Requires (Dev)
- symfony/var-dumper: ~3 || @stable
README
Flexible Template Library. Inspired by Blade (Laravel) and Twig (Symfony).
Tested on PHP 5.6
, ~7
and ~8
.
Installation
Download this source or via Composer:
composer require anovsiradj/cutter
Example
/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
use section()
to define 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
use begin()
and end()
to output-buffer section
<?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() ?>
for more, see /example/
.
Reference
Class Methods
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
Development
TODO:
- single file library / phar?
- inheritance
dynamic pathdynamic view
All suggestions are welcome. Thanks.