Breadcrumbs

Templates With Savant 2

Templating engines are a great asset to any application or website maintained by a development team. It helps to separate design logic and presentation into two sections. This allows the developers to maintain the program and pass the final values to a template. Then the designers and webmasters can easily change the presentation without having to deal with any code.

Many developers use the Smarty template engine. While Smarty offers a nice amount of features that really take templating far and beyond, it is slightly bloated. PHP itself is a templating engine, and there is no need to recreate its syntax.

For templating, I have found Savant (external link) to be exactly what I need, something lightweight and easy to use. Rather than recreating a separate syntax for PHP's features, it just uses PHP. There is also no template compiling. According to Savant itself, it is a "simple, elegant, and powerful alternative to Smarty."

Savant is completely object orientated and has the ability for plugins and output filters. On top of all of this, the syntax used by Savant is extremely simple:

Code: PHP

<?php
require_once 'Savant2.php';
$tpl =& new Savant2();

$title 'Lowter';
$link 'http://www.lowter.com';

// Assign values to template
$tpl->assign('title'$title);
$tpl->assign('link'$link);

$tpl->display('link.tpl.php'); // Display template
?>

Code: PHP

<a href="<?php $this->_($this->link?>"><?php $this->_($this->title?></a>

As you can see, the syntax of Savant is comprehensible and not as bloated as Smarty. For any looping or conditional statements needed you simply use PHP. Some might ask, what use is Savant then? Savant does exactly what a templating engine is designed for, separating design and presentation logic, and it does so in a minimalistic manner.

If you are looking for a simple, easy to use, lightweight templating engine then Savant (external link) is exactly what you are looking for.