Skip to content

Latest commit

 

History

History
83 lines (56 loc) · 3.04 KB

README.md

File metadata and controls

83 lines (56 loc) · 3.04 KB

Phtml

Automation Supported PHP Version GitHub Sponsors Code Coverage Type Coverage Psalm Level Latest Version on Packagist Downloads

A powerful PHP template engine designed to deliver high-performance, extensibility, and security.

Warning

This project is not finished yet, work in progress.

Installation

You can install the package via composer:

composer require ghostwriter/phtml

Star ⭐️ this repo if you find it useful

You can also star (🌟) this repo to find it easier later.

Usage

use Ghostwriter\Phtml\Phtml;

$phtml = Phtml::new('path/to/templates', 'path/to/cache');

$phtml->registerNamespace('html', 'path/to/templates/html');

// File: path/to/templates/html/element/paragraph.phtml
// Content: <p>{{ $message }}</p>

// "html" is the namespace.
// "element" is the directory name inside the namespace.
// "paragraph" is the template filename inside the directory, without the ".phtml" extension.

$html = $phtml->render('html::element.paragraph',['message' => '#BlackLivesMatter']);

echo $html; // <p>#BlackLivesMatter</p>

Advanced Usage

use Ghostwriter\Phtml\Cache\PhtmlCache;
use Ghostwriter\Phtml\Compiler\PhtmlCompiler;
use Ghostwriter\Phtml\Engine\PhtmlEngine;
use Ghostwriter\Phtml\Loader\PhtmlLoader;
use Ghostwriter\Phtml\Renderer\PhtmlRenderer;

$cache = PhtmlCache::new('path/to/cache');
$loader = PhtmlLoader::new('path/to/templates');
$compiler = PhtmlCompiler::new($cache, $loader);
$engine = PhtmlEngine::new($compiler);
$renderer = PhtmlRenderer::new($engine);

$result = $renderer->render(template: 'alert', context: ['message' => '#BlackLivesMatter']);

Credits

Changelog

Please see CHANGELOG.md for more information on what has changed recently.

License

Please see LICENSE for more information on the license that applies to this project.

Security

Please see SECURITY.md for more information on security disclosure process.