talideon.com

Capuccino, Mocchacino, Frappacino, Al Pacino

July 21, 2005 at 10:51PM The World’s Simplest (decent) PHP Templating Engine...

...is PHP, so why not use it?

function include_view($view, $vars=NULL) {
    # Start buffering the generated text.
    ob_start();

    # Process the view.
    if (!is_null($vars)) {
        extract($vars, EXTR_OVERWRITE | EXTR_REFS);
    }
    include("views/$view.php");

    # Grab the generated content and clean up.
    $content = ob_get_contents();
    ob_end_clean();

    return $content;
}
Technorati Search Technorati Search Irish Bloggers

Comments

2 On July 23, 2005 at 21:03, Keith wrote:

I thought you used Smarty. Good to see you’re not though. I’ve never understood the logic behind using the likes of it.

3 On July 24, 2005 at 19:01, Keith Devens wrote:

Back when I was in my architecture astronaut phase trying to write a web framework I played around with Smarty for a bit trying to fit it into the type of design I wanted. It worked, but required a huge nasty hack. I’m out of my astronaut phase now anyway :)

Post a comment

All form information is optional, but it’s a good idea to fill in your name and email address if you want me to take your comment seriously.

Spammers, don’t bother posting crap down here. The site is set up so that legitimate search engines (Google, for instance) won’t index pages with comments on them. Posting crud here only means you’re wasting my time and patience. Shoo!

Real names, please. Please include!
Won’t be displayed. Please include!
Displayed, if present.