Packagist Packagist GitHub tag Packagist GitHub issues GitHub pull requests GitHub last commit GitHub repo size in bytes GitHub code size in bytes Documentation Status

A tiny PHP templating engine.
Tempearly uses Regular Expressions to provide fast but still powerful features to your templates.



Require the module through Composer:

$ composer require mcstreetguy/tempearly

Tempearly registers itself and it's components in the PSR-4 namespace. Ensure you include Composer's autoloader:

include_once 'vendor/autoload.php';


If you don't use Composer you can also download a source archive from GitHub and include the files manually.


(Replace 'master' with your desired version)


First initiate a Tempearly instance by providing the path to your template folder and optionally the file extension of your templates. The extension defaults to .tpl.html but the path has to be provided.

$engine = new MCStreetguy\Tempearly('my/template/folder','.html');

Now you can invoke the rendering process of any template within your template folder as following:


You may structure your templates in subdirectories. Then provide the relative path as template id:


The render(...) function returns the parsed template as string. Thus you may echo it directly to your page, or work on it further as you wish.

User Context

You can provide an optional array of context-variables to the rendering process as seconds argument:

  'foo' => 'Hello World!',
  'bar' => true,
  'baz' => 27

You can also directly pass a Context instance. The use of that class is especially handy if you need to fill it dynamically instead of just passing static values as array.

$context = new MCStreetguy\Tempearly\Context();

$context->push('foo','Hello World!');


You may also pass an array to the Context constructor, making it use that array as context contents. Modifications are still possible afterwards.

$context = new MCStreetguy\Tempearly\Context(array(
  'foo' => 'Hello World!',
  'bar' => true



There is no restriction to the context values, the parameter is defined as mixed. Nevertheless I recommend only using simple types and callables.


Tempearly provides a static minify function that removes all unnecessary whitespaces from an HTML string. Whitespaces are considered unnecessary if they occur multiple times or outside of HTML tags.