View Single Post
Old 06-01-2008, 11:29 PM   #1 (permalink)
Sam Granger
The Acquainted
 
Join Date: Sep 2007
Posts: 126
Thanks: 4
Sam Granger is on a distinguished road
Default Template class - help!!

I have written the following simple class - first of all, if I can improve any parts, please let me know!!

PHP Code:
<?php

/**
 * @author Sam Granger
 * @copyright 2008, *******.com
 */

class Template {

    var 
$template;
    
    function 
__construct($template_file) {

        
$this->template file_get_contents($template_file);

    }
    
    function 
replaceTags($variable$content) {
        
$this->template str_replace('<% ' $variable ' %>'$content$this->template);
    }
    
    function 
displayHTML() {
        echo 
$this->template;
    }

}

?>
Used as following:

PHP Code:
$template = new Template('design.html');
$template->replaceTags('title''Hello!');
$template->replaceTags('message''Under construction');
$template->displayHTML(); 
Whats the best way to implement variables that are outputted from a while or for statement?
Sam Granger is offline  
Reply With Quote