A template engine is not simply a str_replace, it can in short be something like PHP initially was itself, a simply interpreter of commands variable names or expressions can be a simple part of that.
If you want to replace a template engine by native PHP usage, then you can only pray the engine wasn't used extensively and with all it's features, or you have to reprogram much of its parsing engine and variable and expression handling etc etc.
Or you stay with the templates.
$template has to be defined/instanciated at one place. Find the source of this object and you know the used template engine at least. This could very much help mto know aht you want to replace. At the moment it looks you want to replace something quite good, even though it is monolithically only rendering full html pages and not html snippets only. You might rather tackle this on the level of the tlp files and work on the templates instead of the code.
In general, you are deep diving into this, instead of looking at the outmost level of things. What PHP framework is used, what template engine? You might work on framework internals here, you don't do that, unless you are the framework developer.
Bye, Olaf.