Template Engines ... weighing deep on my mind these days.

I use Smarty in my daily work, but it's being "abused" to the point that it's become completely pointless to use it in the first place. It basically functions as a second programming language - with objects being passed in, methods being invoked from the template, our templates have simply become subprograms written in a second programming language.

In my own private work, I've stopped using templates altogether - or rather, I use PHP as the template engine, which results in much smaller templates, and (by enforcement of my own principles) better separation of code and layout.

We keep using it simply because "that's what we use".

Now though, I find myself needing a simple "template engine" that is secure and user-friendly, which will provide users (with basic HTML knowledge) the ability to "program" very simple HTML-centric templates.

"Secure" meaning, this has to be something that won't enable the user to access objects and invoke methods in the underlying application.

"User-friendly" meaning, it has to be simple enough for a person with basic HTML knowledge to write and understand.

Can anyone recommend such an engine? It has to be something fast and lightweight.

Come to think of it, Smarty might actually do the trick, if used properly 😉

Although I wouldn't mind something with a less "programmer" like syntax, and something a lot more lightweight.

Although, then again, I suppose Smarty might not be all that heavy, as such - although it's an enormous script, once a template has been compiled, it doesn't actually load the whole engine when it renders a template, does it?

And as a template author, there's no saying you'd have to learn the full syntax - just the basics.

Your input please! 🙂

Thanks!

    I myself use a very simple template class that only uses str_replace() to replace the things I want. Heres an example of its use:

    require('template.class.inc.php');
    
    $templ = new Template('templates/page.html');
    $templ->AddTag('%TITLE%','This is pages titletext');
    $templ->AddTag('%SOMETHINGELSE%','This is something else');
    echo $templ->Parse();
    

    So if the template is something like this:

    <html>
    <head>
    <title>%TITLE%</title>
    </head>
    <body>
    <div>%SOMETHINGELSE%</div>
    ...
    

    .. It would replace those %TITLE% and %SOMETHINGELSE% to what you want.

    So this is very basic and easy to use and I use it quite heavily on my projects. The class itself is not mine but a german guy did it for our postfixadmin-like post administration in 2002. So its old code but works like a charm 🙂 I can send you the class if you like to try it out.

      From template? You dont 🙂 This is really only a simple search and replace. All the code is created in the template handler. If I do something with my co-worker who is responsiple for the design, I let him do the html-page as it would be(with "lorem ipsum") and then modify that. Designer doenst need to learn some obscure syntax at all because all the code is done by coder and designing by designer 🙂

      Eg. if theres dynamic navigation from database at the left side, I would replace the navigation div with "%LEFTNAVI%" (I use percentmarks but you could ofcourse use anything u like) and do the replace at code side.

        Write a Reply...