Hi, I'm experimenting with using templates. Is this the best/standard/optimal way to do things?
I am basically loading the file, doing a str_replace() on it and then outputting it. I am matching <{ "foo" }> and foo is stored in the array.
<?
function template($pattern,$replace,$file) {
$file = implode("",file($file));
foreach($pattern as $key => $value) {
$pattern[$key] = "<{ \"".$value."\" }>";
}
echo(str_replace($pattern,$replace,$file));
}
$pattern[] = "conf_title";
$replace[] = "Hello World!!! I am working";
$pattern[] = "lang_welcome";
$replace[] = "Welcome to the templates test";
template($pattern,$replace,"./helloworld.tpl");
?>
helloworld.tpl
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><{ "conf_title" }></title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1" />
</head>
<body>
<p><{ "lang_welcome" }></p>
</body>
</html>
Thanks !
- Damo