12-27-2010, 03:44 AM
|
#1 (permalink)
|
|
The Contributor
Join Date: Sep 2008
Location: Miami
Posts: 39
Thanks: 7
|
Template Class Issue
Hello,
I'm having a issue with my template class. I need to output a while statement from user.functions.php but when I do the following.
Code:
$template = new tpl();
$template->set_template('user_profile.phtml');
$template->write('feed', randomUserFeedFunction());
$template->render();
Heres the issue
Instead of Outputting :
Code:
Feed message one 1
Feed message two 2
etc.
in the .feed div it out put it at the top of the template  . Why?
Code:
<?PHP
class template{
protected $file;
protected $values = array();
public function __construct(){ }
# Loads and sets template file
public function set_template($file){
$this->file = $file;
}
# Set
public function set($key, $value){
$this->values[$key] = $value;
}
# Output
public function output(){
if(!file_exists($this->file)){
return '<fieldset style="background:#FFF;padding:5px;border:1px solid #CCC;"><legend><strong style="color:red;">ERROR</strong></legend>File ('.$this->file.') doesn\'t exist.</fieldset>';
}
$output = file_get_contents($this->file);
foreach($this->values as $key => $value){
$tagToReplace = "{".$key."}"; # Find {KEY}
$output = str_replace($tagToReplace, $value, $output);
}
return $output;
}
# Render Template
public function render(){
print $this->output();
}
}
|
|
|