Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/anovsiradj/php-cutter

flexible template library
https://github.com/anovsiradj/php-cutter

composer php php-library php5 php7 template-library

Last synced: 24 days ago
JSON representation

flexible template library

Awesome Lists containing this project

README

        

# Cutter

Flexible Template Library. Inspired by Blade (Laravel) and Twig (Symfony).

Tested on PHP `5.6`, `~7` and `~8`.

## Installation

[Download this source](/anovsiradj/php-cutter/releases) or via [Composer](https://packagist.org/packages/anovsiradj/cutter):

```cmd
composer require anovsiradj/cutter
```

## Example

`/index.php`

```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

```php


= $page_title ?>



section('content') ?>

section('script') ?>

```

`/pages/home.php`

use `begin()` and `end()` to output-buffer section

```php
begin('content') ?>


  • Post title 1

  • Post title 2

  • Post title 3


end() ?>

begin('script') ?>
alert('date today is <?php echo $date_today ?>')
end() ?>
```

for more, see `/example/`.

## Reference

**Class Methods**

```php
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 path~~
- ~~dynamic view~~

All suggestions are welcome. Thanks.

## Reference

- https://laravel.com/docs/5.8/blade
- https://twig.symfony.com/doc/2.x/