https://github.com/ghostwriter/phtml
[WIP]A powerful PHP template engine designed to deliver high-performance, extensibility, and security.
https://github.com/ghostwriter/phtml
ghostwriter php phtml template-engine
Last synced: 6 months ago
JSON representation
[WIP]A powerful PHP template engine designed to deliver high-performance, extensibility, and security.
- Host: GitHub
- URL: https://github.com/ghostwriter/phtml
- Owner: ghostwriter
- License: other
- Created: 2024-07-24T00:41:42.000Z (over 1 year ago)
- Default Branch: 0.1.x
- Last Pushed: 2025-07-27T22:27:23.000Z (6 months ago)
- Last Synced: 2025-07-28T00:22:00.849Z (6 months ago)
- Topics: ghostwriter, php, phtml, template-engine
- Language: PHP
- Homepage: https://github.com/ghostwriter/phtml
- Size: 503 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Codeowners: .github/CODEOWNERS
- Security: SECURITY.md
Awesome Lists containing this project
README
# Phtml
[](https://github.com/sponsors/ghostwriter)
[](https://github.com/ghostwriter/phtml/actions/workflows/automation.yml)
[](https://www.php.net/supported-versions)
[](https://packagist.org/packages/ghostwriter/phtml)
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:
``` bash
composer require ghostwriter/phtml
```
### Star ⭐️ this repo if you find it useful
You can also star (🌟) this repo to find it easier later.
## Usage
```php
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:
{{ $message }}
// "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; //
#BlackLivesMatter
```
### Advanced Usage
```php
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
- [Nathanael Esayeas](https://github.com/ghostwriter)
- [All Contributors](https://github.com/ghostwriter/phtml/contributors)
### Changelog
Please see [CHANGELOG.md](./CHANGELOG.md) for more information on what has changed recently.
### License
Please see [LICENSE](./LICENSE) for more information on the license that applies to this project.
### Security
Please see [SECURITY.md](./SECURITY.md) for more information on security disclosure process.