mattwright Posted June 19, 2007 Share Posted June 19, 2007 How can i loop it so i can make more links? (tried to remove excess code to make it easier to understand/read) Ok my code looks like this <?php include "class_template.php"; $global = new template; $vars = array("linkname" => "Home", "link" => "www.home.com"); $page = $global->make_template("global"); echo $global->insert_variables($page, $vars); ?> and my global template file looks like Menu <a href="{link}">{linkname}</a> and my class_template looks like this <?php class template { var $template_dir = 'templates/'; var $file_ext = '.tpl'; var $buffer; function make_template($file) { $this->buffer = file_get_contents( $this -> template_dir . $file . $this -> file_ext ); return $this->buffer; } function insert_variables($input, $vars) { $search = preg_match_all('/{.*?}/', $input, $matches); for($i = 0; $i < $search; $i++) { $matches[0][$i] = str_replace(array('{', '}'), null, $matches[0][$i]); } foreach($matches[0] as $value) { $input = str_replace('{' . $value . '}', $vars[$value], $input); } return $input; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/56126-looping-with-template-class/ Share on other sites More sharing options...
teng84 Posted June 19, 2007 Share Posted June 19, 2007 are you the one who created the class ??? Quote Link to comment https://forums.phpfreaks.com/topic/56126-looping-with-template-class/#findComment-277249 Share on other sites More sharing options...
mattwright Posted June 19, 2007 Author Share Posted June 19, 2007 Its from an old tutorial i had on my computer, got a solution? Quote Link to comment https://forums.phpfreaks.com/topic/56126-looping-with-template-class/#findComment-277252 Share on other sites More sharing options...
teng84 Posted June 19, 2007 Share Posted June 19, 2007 the class generate the links right???? then loop the part that is calling the function in the class that creates links Quote Link to comment https://forums.phpfreaks.com/topic/56126-looping-with-template-class/#findComment-277255 Share on other sites More sharing options...
mattwright Posted June 19, 2007 Author Share Posted June 19, 2007 I dont want to loop every single thing only the links Quote Link to comment https://forums.phpfreaks.com/topic/56126-looping-with-template-class/#findComment-277262 Share on other sites More sharing options...
teng84 Posted June 19, 2007 Share Posted June 19, 2007 weird are trying to say you want lots of same links well initialize a number of loop and loop the result of your class(link) Quote Link to comment https://forums.phpfreaks.com/topic/56126-looping-with-template-class/#findComment-277267 Share on other sites More sharing options...
gtk Posted June 19, 2007 Share Posted June 19, 2007 Why dont you use teh template class Aviliable From here. See it on http://zigmoyd.sourceforge.net/man/template.php#template. Installation and Instruction It comes with great support you can directly chat with the developers of this Class anytime. and its really too easy and Small. Quote Link to comment https://forums.phpfreaks.com/topic/56126-looping-with-template-class/#findComment-277366 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.