What you are looking for is a template system. You need to write a parser to parse these {%THEVARIABLE%} type variables.
It could be as simple as...
<?php
$replacewith = 'foo';
$template = file_get_contents("template.tpl");
$template = str_replace('{%THEVARIABLE%}',$replacewith,$template);
echo $template;
?>
Or obviously alot more complex. These templates you speak of are not a php feature, you need to build all this yourself or downlaod a template parser/system/engine.