
April 20th, 2007, 08:23 AM
|
|
Contributing User
|
|
Join Date: Apr 2007
Posts: 63
Time spent in forums: 10 h 18 m 28 sec
Reputation Power: 2
|
|
|
RE: help : looping for template
not sure if you still reading this but hey this topic is something im interested in so ill get it started again.
What you have to do is separate the function that inputs files and the function that replaces tags.
Heres the php code
php Code:
Original
- php Code |
|
|
|
<?php class Page { var $page; function Page($template = "index.html") { $this-> page = join("", file("template/". $template)); else die("Template file $template not found."); } function parse($file) { include($file); return $buffer; } function file_replace ($file = array()) { foreach ($file as $name => $loc) { $this->page); } else die("No file designated for inclusion."); } function replace_tags ($tags = array()) { { foreach ($tags as $tag => $data) { $this->page); } } else { die("No tags designated for replacement."); } } ?>
and in the index.php file which is the template file that calls this class you put
php Code:
Original
- php Code |
|
|
|
<?php require_once("template_control.php"); $page = new Page(); //this has to go before replacing the tags $page-> file_replace(array( "head" => "template/header.html", "menu" => "template/main_nav.html", "left" => "template/sec_nav.html", "right" => "template/content.html", "footer" => "template/footer.html" )); //this has to go after you include the files $page-> replace_tags(array( "TITLE" => "Testing templating system!", "HEADER" => "Welcome to my website!", "FOOTER" => "the footer is copywrited on." )); $page->output(); ?>
|