1. Go to this page and download the library: Download xtompie/tpl library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
xtompie / tpl example snippets
use Xtompie\Tpl\Tpl;
$tpl = new Tpl();
echo $tpl->__invoke('page.tpl.php', ['title' => 'Foobar']);
phtml
/** @var Xtompie\Tpl\Tpl $this */
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
/** @var App\Shared\Tpl\Tpl $this */
/** @var Xtompie\Tpl\Tpl $this */
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.