LegosJedi Posted March 23, 2007 Share Posted March 23, 2007 Okay, so I've written my own template class, but for some reason, it's not replacing any of the keys in the templates. Here's the code for the template class: <?php class template { var $all = array(); var $tmpl_name; function output($filename, $existing = "", $replace = "") { //global $settings; //$file = $settings['siteroot'].$settings['tmpl_dir'].$this->tmpl_name.$filename.".tpl"; $file = CM_ROOT.$this->tmpl_name.$filename.".tpl"; if(!file_exists($file)) { echo '<b>Error:</b> Template file cannot be located.<br /><br /> We are trying to find <a href="'.$file.'">'.$file.'</a> in.<br /> <b>PROCESS SKIPPED.</b> <font color="red">Please notify the administrator about this problem.</font><hr />'; } else { $template = file_get_contents($file); $template = str_replace("{".$existing[$filename]."}", $replace[$filename], $template); $template = str_replace("{".$this->all['existing']."}", $this->all['replace'], $template); echo $template; } } } ?> When $existing and $replace are inputted, they're supposed to be arrays. Quote Link to comment Share on other sites More sharing options...
monk.e.boy Posted March 23, 2007 Share Posted March 23, 2007 looks like it should work. Try putting some 'echo's in there to see the values. BTW get a good debugger for PHP, makes this sort of thing 10,000% easier to debug. I use NuSphere and it is cool. monk.e.boy Quote Link to comment Share on other sites More sharing options...
per1os Posted March 23, 2007 Share Posted March 23, 2007 The curly braces may need to be escaped I believe, but yea try echoing the variables to make sure they contain what you expect. Quote Link to comment Share on other sites More sharing options...
LegosJedi Posted March 23, 2007 Author Share Posted March 23, 2007 Okay, I will. Thanks for the tips! Quote Link to comment Share on other sites More sharing options...
LegosJedi Posted March 23, 2007 Author Share Posted March 23, 2007 (Sorry for double post) Okay, I tried escaping the brackets, and that didn't work. Then I echoed the variables, and they all contained what they needed to contain. Any other tips? Quote Link to comment Share on other sites More sharing options...
per1os Posted March 23, 2007 Share Posted March 23, 2007 I think you only would need to escape one bracket. I am not sure which but give that a try. Quote Link to comment Share on other sites More sharing options...
LegosJedi Posted March 23, 2007 Author Share Posted March 23, 2007 Nope. Still doesn't work. Quote Link to comment Share on other sites More sharing options...
per1os Posted March 23, 2007 Share Posted March 23, 2007 Maybe try ereg_replace() http://us3.php.net/manual/en/function.ereg-replace.php Quote Link to comment Share on other sites More sharing options...
LegosJedi Posted March 23, 2007 Author Share Posted March 23, 2007 That somewhat worked. Some of the things that need to be displayed are displayed, but they aren't where they are supposed to be. Link Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.