https://github.com/xtompie/tpl
https://github.com/xtompie/tpl
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/xtompie/tpl
- Owner: xtompie
- Created: 2024-09-07T12:03:21.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2025-07-09T19:53:32.000Z (about 1 year ago)
- Last Synced: 2025-12-14T17:57:23.764Z (7 months ago)
- Language: PHP
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Tpl
Tpl native PHP template system.
Simple, lightweight, no dependencies, low abstraction, low features, easy to extend.
```php
__invoke('page.tpl.php', ['title' => 'Foobar']);
```
`page.tpl.php`:
```phtml
= $this->e($title) ?>
```
- uses native PHP
- not auto escape, but `vendor/bin/xtompie-tpl-audit.sh -p src -s .tpl.php` can be used
- no sections
- no blocks
- no namespaces
- autocompletion using ``
## Requiments
PHP >= 8.0
## Installation
Using [composer](https://getcomposer.org/)
```shell
composer require xtompie/tpl
```
## Full feature example
```phtml
// Extend Tpl for customization, set templatePathPrefix, add helpers
// src/App/Shared/Tpl/Tpl.php
namespace App\Shared\Tpl\Tpl;
use Xtompie\Tpl\Tpl as BaseTpl;
class Tpl extends BaseTpl
{
protected function templatePathPrefix(): string
{
return 'src/';
}
protected function date(int $time): string
{
return $this->e(date('Y-m-d H:i:s', $time));
}
}
// src/App/Test/Ui/Controller/TestController.php
namespace App\Test\Ui\Controller;
use App\Shared\Tpl\Tpl;
class TestController
{
public function __construct(
private Tpl $tpl
) {
}
public function __invoke(): string
{
return $this->tpl->__invoke('Test/UI/Tpl/content.tpl.php', ['title' => 'foobar']);
}
}
// src/Test/UI/Tpl/content.tpl.php - first level
// keep template file names with `.tpl.php` suffix e.g. easy exclude from phpstan
push('Test/UI/Tpl/layout.tpl.php', ['title' => $title]); ?>
= $this->e($title) ?>
// src/Test/UI/Tpl/layout.tpl.php - second level
push('Test/UI/Tpl/head.tpl.php', ['title' => $title]); ?>
= $this->render('Test/UI/Tpl/navbar.tpl.php') ?>
= $this->content() ?>
// src/Test/UI/Tpl/navbar.tpl.php
// src/Test/UI/Tpl/head.tpl.php - third level
= $this->e($title) ?>
= $this->content() ?>
```