ark / template
Native PHP template engine
v0.1.2
2016-04-26 10:09 UTC
This package is auto-updated.
Last update: 2024-11-13 22:53:39 UTC
README
Native PHP template engine
Installation
composer require ark/template
Usage
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();?>
Markups
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');?>
Template Functions
Escaping:
<?=$this->escape($username)?> <!-- or for short --> <?=$this->e($username)?>
Filter:
<?=$this->filter($username, 'strtolower|trim')?> <?=$this->e($username, 'strtolower|trim');?>