gijew Posted March 16, 2010 Share Posted March 16, 2010 I'm writing a small template class. Easy - works. I decided to get tricky and add a modifier to the template variables. The whole thing is too much to get in to so I'll try and keep it small - hopefully someone can understand my ramblings Example tpl var ::content->linkset:: Example tpl var w/modifier ::content->linkset[5]:: Using the modifier I would get (x) amount of records from an array. That code all works too but before I continue I should add that once all of the template variables have been replaced it writes everything to a file for caching purposes. The problem is when the template contains more than one modifier it repeats the last one over and over again in the final output (and yes, it repeats the last one in the array). Experience has taught me that the solution would be to reset the counter before it loops again but for whatever reason it's not working. Here's some code to see if someone can spot the problem. I took out a few things but this should be the gist. Thanks in advance. <?php // read from tpl $file = $var['path'] . $var['themes'] . $tpl . '/' . $var['file_index']; $tplr = fopen($file, 'r'); $template = fread($tplr, filesize($file)); // special output if (preg_match_all('/(::content->linkset\\[([0-9]*)\\]::)/', $template, $results)) { // open file for writing $tplw = fopen($file, 'w'); // loop through results for ($i = 0; $i < count($results); $i++) { $output = fwrite($tplw, preg_replace('/(::content->links_body\\[([0-9]*)\\]::)/', $this->content_linkset('body', $results[2][$i]), $template)); } } ?> If for whatever reason you want to see the entire code I'll post it. It's not horribly long (48 lines) but I know how frustrating it is to sift through all that crap when you're trying to help Quote Link to comment Share on other sites More sharing options...
gijew Posted March 16, 2010 Author Share Posted March 16, 2010 I just needed a break. I fixed it. Long story short is I just threw the output of the loop into an array and did a str_replace with the contents of the array. 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.