PHP Classes

ExTemplate: Extensible template engine with callable functions

Recommend this page to a friend!
  Info   View files Example   View files View files (7)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 240 All time: 8,018 This week: 65Up
Version License PHP version Categories
extemplate 1.0Public Domain5.4PHP 5, Templates


This class implements an extensible template engine with callable functions.

It can register new template commands assigned by a name and a callable function that will define the meaning and result of the command when it is found on a template.

The template engine parses a template file to find marks enclosed in curly braces and replaces them with the result of the registered commands defined by the template marks.

Innovation Award
PHP Programming Innovation award nominee
April 2015
Number 3

Prize: One book of choice by Packt
Many template engines can be extended by the means of plugins that implement special commands for template tags.

This package implements a template engine that can be extended dynamically with new commands implemented with custom registered callable functions.

Manuel Lemos
Picture of Matthew Knowlton
  Performance   Level  
Name: Matthew Knowlton is available for providing paid consulting. Contact Matthew Knowlton .
Classes: 6 packages by
Country: United States United States
Age: 28
All time rank: 2038291 in United States United States
Week rank: 388 Up42 in United States United States Up
Innovation award
Innovation award
Nominee: 4x

Winner: 1x





$template = new template('template.demo.php');


$template->add_command('includeStyles', function ($params) use ($template){
'<link rel="stylesheet" type="text/css" href="'.$params[0].'"/>'."\r\n";

$template->add_command('includeScript', function ($params) use ($template){
'<script type="text/javascript" src="'.$params[0].'"></script>';

'HeaderFile' => 'demo.header.php',
'FooterFile' => 'demo.footer.php',
'ScriptsFile' => 'demo.scripts.js',
'StylesFile' => 'demo.styles.css',
'PageTitle' => 'Benefits of using a Templating Engine',
'BenefitsOfTemplates' => array(
'Abstraction between Code & Output',
'Simplification of Output Handling',
'Sandboxing User Created Layouts',
'Easier for Non-programmmers to Write/Read',
'Easy data handoff between Front-End & Back-End Developers',
'Simple data escaping implementation'

$template->add_macro('isLoggedIn', (bool)(isset($_SESSION['UserName'])));
$template->add_macro('signInLink', 'demo.signin.php');

$template->add_macro('UserName', $_SESSION['UserName']);




  Files folder image Files  
File Role Description
Plain text file template.class.php Class Class Source
Accessible without login HTML file Doc. Documentation
Accessible without login Plain text file template.commands.php Aux. A few useful commands
Accessible without login Plain text file template.demo.php Example Example template file
Accessible without login Plain text file template.example.php Example Example PHP for proccessing a template
Accessible without login Plain text file demo.footer.php Aux. Footer file for the demo
Accessible without login Plain text file demo.header.php Aux. Template header file for the demo

 Version Control Unique User Downloads Download Rankings  
This week:0
All time:8,018
This week:65Up