Sep 1, 2010

The Smallest Templating Engine

A templating engine comes really handy when programming in PHP. Here's the smallest one you can use -

function tmpl($tmpl_name, $data) {

    $tmpl_dir = 'tmpl/';
    ob_start();
    include ("$tmpl_dir$tmpl_name.php");
    return ob_get_clean();
}


That's it. No other libraries or frameworks required. I think the simplicity and ease of PHP make it the best web language out there.