Native PHP template engine
Native PHP template engine, (*1)
composer require ark/template
use Ark\Template\Engine; $template = new Engine('/path/to/templates/root'); $template->render('index.php', [ 'username' => 'hello' ]);
layout.php:, (*2)
<!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:, (*3)
extend('layout.php');?> begin('title');?>Page Titleend();?> begin('content');?> Page Content end();?> begin('footer');?> Custom footer end();?>
Declare layout:, (*4)
<?php $this->extend('layout.php');?>
Declare a block:, (*5)
block('blockname');?> begin('blockname');?> Block content end();?>
Include another template:, (*6)
<?php $this->render('another.php');?>
Escaping:, (*7)
<?=$this->escape($username)?> <!-- or for short --> <?=$this->e($username)?>
Filter:, (*8)
<?=$this->filter($username, 'strtolower|trim')?> <?=$this->e($username, 'strtolower|trim');?>