Andreas Runfalk

Litter

Litter was a proof of concept template engine for PHP. Like many other popular template engines at the time it supports advanced features like template inheritance (like Twig and Jinja2), but unlike many alternatives it uses PHP files as templates. This allows the library to be very small while maintaining a rich feature set. The core functionality is implemented in under 500 lines of code, including API documentation. It also provides XSS protection, encoding aware string manipulation and iteration helpers.

The template engine was never used in a real project, but it was still interesting and worthwhile to implement it.

<?php
    // Example of template inheritance
    // This template inherits from base.php
    $l = new Litter;
?>
<?php $l->extending("base.php"); ?>
    <?php $l->block("baz"); ?>buz<?php $l->end(); ?>
<?php $l->done(); ?>