2017 © Pedro Peláez
 

library tooolooop

PHP7 lightweight native template engine

image

romanzaycev/tooolooop

PHP7 lightweight native template engine

  • Thursday, February 15, 2018
  • by romanzaycev
  • Repository
  • 1 Watchers
  • 1 Stars
  • 7 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

# Tooolooop

Build status Code coverages Code climate Latest Stable Version Total Downloads, (*1)

PHP7 lightweight native templates., (*2)

Installation

via Composer:, (*3)

composer require romanzaycev/tooolooop

Usage

make('page');
$template->assign(['text' => 'Lorem ipsum']);

echo $template->render();
```

`views/page.php`:
```html
extend('layout') ?>

<section>
  =$this->e($text)?>
</section>

start('footer') ?>
<footer>
  Some footer content.
</footer>
end() ?>

views/layout.php:, (*4)

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Example</title>
</head>
<body>
  <main>
    <h1>Example</h1>
    <?=$this->block('content')?>
  </main>

  =$this->block('footer')?>
</body>
</html>

Need more examples?, (*5)

Requires

PHP >= 7.2.0, (*6)

Extending library

PSR-11 container support

You can use a PSR-11 compatible container and inject dependencies into objects that are generated inside the library (Scope):, (*7)

<?php

use Romanzaycev\Tooolooop\Engine;
use Psr\Container\ContainerInterface;

/** @var ContainerInterface $container */
$container = ...; // Initialize PSR-11 container
                  // and define implementation of Romanzaycev\Tooolooop\Scope\ScopeInterface
$engine = new Engine(__DIR__ . '/views');
$engine->setContainer($container);
$template = $engine->make('page'); // <-- Scope in this template will be obtained from container

You can define the implementation of Romanzaycev\Tooolooop\Scope\ScopeInterface in the container configuration and engine instances Scope through it., (*8)

⚠️ ATTENTION! Make sure that the container returns a new instance of Scope all time! Cached Scope instance does not work., (*9)

User scope

Otherwise, you can specify a custom implementation of the class via $engine->setScopeClass():, (*10)

<?php

use Romanzaycev\Tooolooop\Engine;
use Romanzaycev\Tooolooop\Scope\Scope;
use Romanzaycev\Tooolooop\Scope\ScopeInterface;

class UserSpecificScope extends Scope implements ScopeInterface {
    // Implement your additions, ex. widget system :-)
}

$engine = new Engine(__DIR__ . '/views');
$engine->setScopeClass(UserSpecificScope::class);

Testing

composer run test

The Versions

15/02 2018

dev-master

9999999-dev

PHP7 lightweight native template engine

  Sources   Download

MIT

The Requires

  • php >=7.1.0

 

The Development Requires

by Roman Zaycev

templating templates views romanzaycev

25/12 2017

0.3.0

0.3.0.0

PHP7 lightweight native template engine

  Sources   Download

MIT

The Requires

  • php >=7.1.0

 

The Development Requires

by Roman Zaycev

templating templates views romanzaycev

25/12 2017

0.2.1

0.2.1.0

PHP7 lightweight native template engine

  Sources   Download

MIT

The Requires

  • php >=7.1.0

 

The Development Requires

by Roman Zaycev

templating templates views romanzaycev

25/12 2017

0.2.0

0.2.0.0

PHP7 lightweight native template engine

  Sources   Download

MIT

The Requires

  • php >=7.1.0

 

The Development Requires

by Roman Zaycev

templating templates views romanzaycev

12/12 2017

0.1.2

0.1.2.0

PHP7 lightweight native template engine

  Sources   Download

MIT

The Requires

  • php >=7.1.0

 

The Development Requires

by Roman Zaycev

templating templates views romanzaycev

09/12 2017

0.1.1

0.1.1.0

PHP7 lightweight native template engine

  Sources   Download

MIT

The Requires

  • php >=7.1.0

 

The Development Requires

by Roman Zaycev

templating templates views romanzaycev

09/12 2017

0.1.0

0.1.0.0

PHP7 lightweight native template engine

  Sources   Download

MIT

The Requires

  • php >=7.1.0

 

The Development Requires

by Roman Zaycev

templating templates views romanzaycev