Not precisely sure what "replacement variables" are in this context, but at its simplest a template is just a wodge of text that one uses things like str_replace() or preg_replace() to find certain strings that are marked out in some way (I guess these are the "replacement variables" you're referring to) and then replaces them with the real content to flesh the template out into a full page. As the template system gets increasingly advanced, the search/replacement task gets more elaborate, but that's pretty much what it boils down to.
With such a vague question it's hard to give anything more than a vague answer. There are half-a-dozen articles at http://www.phpbuilder.com/ that may be relevant.