greg-md/php-view

A powerful View for PHP.

v1.0.0 2017-01-20 21:22 UTC

This package is auto-updated.

Last update: 2024-12-24 20:33:32 UTC


README

StyleCI Build Status Total Downloads Latest Stable Version Latest Unstable Version License

A powerful View for PHP.

Table of Contents:

Requirements

  • PHP Version ^7.1

Compilers

  • PHP
  • Blade

How It Works

First of all, you have to initialize a Viewer:

$viewsDirectory = __DIR__ . '/views';

$viewer = new \Greg\View\Viewer($viewsDirectory);

Optionally, you can add a view compiler. For example a Blade Compiler specially created for the Viewer:

// Turn it to a callable, to load only when using blade templates.
$viewer->addExtension('.blade.php', function () {
    $compiledViewsDirectory = __DIR__ . '/compiled';

    return new \Greg\View\ViewBladeCompiler($compiledViewsDirectory);
});

By default it will use Renderer as an instance of a template.

Note: If you want to use your own compiler, it has to be an instance of Compiler Strategy.

Now, you can render views where you want in your application.

Create a template file in the views directory. For example welcome.blade.php:

<html>
    <body>
        <h1>Hello, {{ $name }}</h1>
    </body>
</html>

Use welcome template in your application:

$content = $viewer->render('welcome', [
    'name' => 'Greg',
]);

echo $content;

Documentation

License

MIT © Grigorii Duca

Huuuge Quote

I fear not the man who has practiced 10,000 programming languages once, but I fear the man who has practiced one programming language 10,000 times. #horrorsquad