Quote Originally Posted by Young Twig
What I often do is assign everything (or near everything) to a variable, much like in a templating system. But instead of assigning it to a member of a tpl_var array, I just throw it all in the global scope and include the template.

I'm sure tons of people are against the whole global concept, and I'm sure you could do things more elegantly, but I've found it to be the simplest, easiest method. It's also quite reminiscent of a template engine. Just with cooler syntax.
I had another look at my earlier reply and fixed some things. Instead of making everything global, how about playing around with extract() and function scope?

So there's a test.php:

PHP Code:

= array // practically would be taken from database
'username' => 'Fred'
'page_title' => 'Admin'

view($array$file// Two line templating system?


Then admin.php
PHP Code:
<?php view(array ('page_title' => $page_title), 'header.php'?>
        Welcome back, <?=$username?>!
<?php view(array(), 'footer.php'?>
PHP Code:
PHP Code:
Each call of view() creates a scope that the variables are unpacked into for the PHP template, as far as I have tested. Though I'd be interested in what other people think of the code; I've never used it in a production environment.