PHP Template Class

PHP Template Class


With PHP template class you can completely separate your PHP code from your HTML without sacrificing performance or dealing with dozens of additional files to do so.

Table of Contents


  • Easy to install
  • Lightweight single PHP file (12kb)
  • PHP 5 OOP makes it easy to extend
  • Caches compiled templates until they’re modified
  • Combines css and javascript files into single files
  • Compresses css and javascript files using YUI Compressor
  • Supports if, elseif, else, and include from within template
  • Supports looped data within template


  • Supports PHP 5.x or later.
  • Ability to execute .jar files via PHP’s exec() function is required for compressing css and javascript files.


11/04/11 v1.5

  • Updated the code in which the cache file’s validity is checked.

10/21/11 v1.4

  • Added another optional parameter to the display() function that allows you to combine css and js files into a single file. (Caches combined file until any of the individual files are modified).

    // Will combine css and javascript files to 'combined.css' and 'combined.js'

    $css = array('global.css', 'style.css');

    $template->display('Page Title', 'template-file.html', $css, 'jquery.js', 'combined');
  • Added the option to compress css and js files using the YUI Compressor when the above parameter is used. (Falls back to uncompressed version if compression fails).

6/29/11 v1.3

  • Added ability to pass css and javascript files through the template class via the display() function by either string or array.

    $css = array('global.css', 'style.css');

    $template->display('Page Title', 'template-file.html', $css, 'jquery.js');

    <!-- EMBED CSS -->

    <!-- EMBED JS -->

08/13/10 v1.2

  • Cache folder is now created if it doesn’t exist

08/08/10 v1.1

  • Configuration settings can now be passed to class when called:

    $config = array('root' => 'template/', 'cache' => 'cache/');

    $template = new template($config);



Please enter your comment!
Please enter your name here