PHP Savant

By Deane Barker on July 27, 2005

Savant Template Engine: A good look at Savant, which is a template engine for PHP. Sort of.

Comparing Savant to Smarty is difficult. Yes they are both template engines, but Savant does not compile its templates. Nor does it have its own built in scripting syntax. It uses PHP.

Savant is a lot like using PHP amidst HTML, but it concentrates everything in an object. Of course, this doesn’t stop anyone from going “outside” the object and just writing PHP like crazy in their template, but it’s not designed to be sandboxed.

A lot of template engines are meant for non-programmers to write code, and I gather Savant isn’t like that — it’s just to let the programmer keep his presentation separate from his code. I’ll probably stick with Smarty, but Savant is nicely done.

Gadgetopia
What This Links To

Comments

  1. Hi Deane —

    You said, “A lot of template engines are meant for non-programmers to write code, and I gather Savant isn’t like that — it’s just to let the programmer keep his presentation separate from his code. I’ll probably stick with Smarty, but Savant is nicely done.”

    First, thanks for looking at Savant, and thanks for the good words. :-)

    I want to elaborate on the first poster’s link to the Savant compiler documentation. The linked page points out that, by default, Savant does not compile templates. It expects templates to be in PHP; in this mode, Savant is mostly a developer’s tool, not a designer’s tool.

    However, you can write any compiler you like and hook it into Savant. As long as the compiler returns a path to a compiled PHP script, you can base it on any kind of markup you like, such as simple variable substitution, or XSL/TAL, or domain-specific markups, or even a Smarty-like language.

    This means that the compiling has been de-coupled from the variable-collection and processing aspects of the template system. If you like one kind of markup, you can write a compiler for it; if you like another, you can write a different compiler — but you won’t have to change the business-logic that assigns variables, picks templates, manages plugins, and so on.

    Savant2 comes with a “basic” compiler as a proof-of-concept, but of course you can modify it (or write an entirely new one) to match your own tastes. So, not only is Savant fully capable of sandboxing, the sandbox can be of your own design for your own purposes. :-)

    For more points and discussion on this matter, see RevJim’s posts at:

    http://revjim.net/item/10170/

    http://revjim.net/item/10171/

    Hope this helps to highlight some of the lesser-known capabilities of Savant in relation to Smarty; and thanks for the post. :-)

    — pmj

Comments are closed. If you have something you really want to say, email editors@gadgetopia.com and we‘ll get it added for you.