Native PHP template engine
composer require ark/template
use Ark\Template\Engine;
$template = new Engine('/path/to/templates/root');
$template->render('index.php', [
'username' => 'hello'
]);
layout.php:
<!DOCTYPE html>
<html>
<head>
<title><?php $this->block('title');?></title>
</head>
<body>
<?php $this->block('header');?>
<?php $this->begin('content');?><?php $this->end();?>
<?php $this->block('footer');?>
</body>
</html>
index.php:
<?php $this->extend('layout.php');?>
<?php $this->begin('title');?>Page Title<?php $this->end();?>
<?php $this->begin('content');?>
Page Content
<?php $this->end();?>
<?php $this->begin('footer');?>
Custom footer
<?php $this->end();?>
Declare layout:
<?php $this->extend('layout.php');?>
Declare a block:
<!-- empty block -->
<?php $this->block('blockname');?>
<!-- block with content -->
<?php $this->begin('blockname');?>
Block content
<?php $this->end();?>
Include another template:
<?php $this->render('another.php');?>
Escaping:
<?=$this->escape($username)?>
<!-- or for short -->
<?=$this->e($username)?>
Filter:
<?=$this->filter($username, 'strtolower|trim')?>
<?=$this->e($username, 'strtolower|trim');?>