TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Advanced PHP Programming (http://www.talkphp.com/advanced-php-programming/)
-   -   Template Class Issue (http://www.talkphp.com/advanced-php-programming/5659-template-class-issue.html)

tego10122 12-27-2010 03:44 AM

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();
        }
}


wGEric 12-28-2010 07:08 PM

Your template class isn't matching up with the first code you posted. Is there another class that is named tpl? Reason I ask is there isn't a write method in your code. I'm guessing the issue is in that method.


All times are GMT. The time now is 02:47 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0