You would need to manually parse through the text in the file and look for things like an if statement then turn it back into PHP. I don't know of a tutorial that does it all. The template engine smarty must have something like this, so you could always look at their code and learn from it...
I tend to use the PHP alternative syntax in template files because its so much easier than doing what you want to do. http://uk3.php.net/alternative_syntax