The idea is to separate Business Logic from Presentation Logic. There is logic in both.
Then there's further sub-divisions of varying worth. Separating Content from Variable Logic from Layout Logic from...
The fact is escaping from logic in templates is quite difficult, and (in a sense) impossible without loosing separation of HTML from PHP Variables. (i.e. adding tags to php variables - not the templates). Taking that route is messy. Roja knows all about that kind of messy from BNT. I had my own share working on another legacy PHP game - it is quite literally a nightmare.
The most efficient route I know is to:
a) Separate variable data from both PHP and the HTML Templates
Simply put. If it changes, put it in a separate holder - either a distinct array, or some form of data class. I typically use a ViewData class - just an overblown associative array all told. Smarty et al. will do this when you call assign().
b) Process variable data within PHP, not Presentation Logic.
Bascially, if you need to do something unrelated to presentation do it in the PHP files. This includes all data look ups (within reason), transfer of objects to array (if any data objects need to be template assigned) etc. Escaping is (arguably) also a PHP task - not presentation. My main factor in the decision is whether the logic I'm adding to the template can be both used and understood by the template designer. So count() is probably bad, if..else obviously okay, and escaping a definite no-no (that's the developers job, not the designers!).
c) Templates should only contain Presentation logic.
Stuff like looping for generating tables, or other html, conditionals over alternate content, etc. are all presentation logic to a large degree. The content in these cases is usually static - so moving this into PHP simply negates the whole point of separating logic.
On template engines - many will handle all this for you. Smarty is probably the most popular. The one issue I have with Smarty is that's its overly complex. It does not strictly separate Logic (it seems more focused on separating PHP from HTML which is over the edge). It requires a separate language (which at the end of the day is miraculously transformed into PHP

). It's a bit bloated (all those processing plugins, etc.).
Another alternative is Savant 2 - this actually utilises the common PHP we all know. Assuming you trust your template writers (they'll be using basic PHP, could add bad things) it's quite a good engine. Since it uses native PHP, there's no new template language to learn, and it actually follows a similar base API to Smarty (so its easy to add as an alternate library).