https://github.com/greg-md/php-view
A powerful View for PHP.
https://github.com/greg-md/php-view
blade greg-md greg-php php php-view view viewer web-artisans
Last synced: 3 months ago
JSON representation
A powerful View for PHP.
- Host: GitHub
- URL: https://github.com/greg-md/php-view
- Owner: greg-md
- License: mit
- Created: 2016-10-15T16:54:59.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2019-07-24T07:47:34.000Z (over 6 years ago)
- Last Synced: 2025-03-11T10:21:52.999Z (11 months ago)
- Topics: blade, greg-md, greg-php, php, php-view, view, viewer, web-artisans
- Language: PHP
- Homepage:
- Size: 120 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Greg PHP View
[](https://styleci.io/repos/71001054)
[](https://travis-ci.org/greg-md/php-view)
[](https://packagist.org/packages/greg-md/php-view)
[](https://packagist.org/packages/greg-md/php-view)
[](https://packagist.org/packages/greg-md/php-view)
[](https://packagist.org/packages/greg-md/php-view)
A powerful View for PHP.
# Table of Contents:
* [Requirements](#requirements)
* [Compilers](#compilers)
* [How It Works](#how-it-works)
* [Documentation](#documentation)
* [License](#license)
* [Huuuge Quote](#huuuge-quote)
# Requirements
* PHP Version `^7.1`
# Compilers
- PHP
- Blade
# How It Works
**First of all**, you have to initialize a [Viewer](docs/Viewer.md):
```php
$viewsDirectory = __DIR__ . '/views';
$viewer = new \Greg\View\Viewer($viewsDirectory);
```
**Optionally**, you can add a view compiler. For example a [Blade Compiler](docs/ViewBladeCompiler.md) specially created for the [Viewer](docs/Viewer.md):
```php
// 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](docs/Renderer.md) as an instance of a template._
_Note:_ If you want to use your own compiler, it has to be an instance of [Compiler Strategy](docs/CompilerStrategy.md).
**Now**, you can render views where you want in your application.
Create a template file in the views directory. For example `welcome.blade.php`:
```blade
Hello, {{ $name }}
```
Use `welcome` template in your application:
```php
$content = $viewer->render('welcome', [
'name' => 'Greg',
]);
echo $content;
```
# Documentation
* [Viewer](docs/Viewer.md) - The view manager;
* [Renderer](docs/Renderer.md) - Instance of a template. Could be accessed via `$this` variable in the template.
* [Loader](docs/Loader.md) - A special loader for [Renderer](docs/Renderer.md) which will give access only to its public properties and methods;
* [Blade Compiler](docs/BladeCompiler.md) - An independent template compiler;
* [View Blade Compiler](docs/ViewBladeCompiler.md) - An extended [Blade Compiler](docs/BladeCompiler.md), specially for the [Viewer](Viewer.md).
* [Compiler Strategy](docs/CompilerStrategy.md) - A strategy for custom compilers;
* [View Compiler Strategy](docs/ViewCompilerStrategy.md) - A strategy for custom [Viewer](docs/Viewer.md) compilers;
# License
MIT © [Grigorii Duca](http://greg.md)
# Huuuge Quote
