View Single Post
Old 01-07-2009, 11:54 PM   #1 (permalink)
Scottymeuk
The Contributor
 
Join Date: Jan 2009
Posts: 40
Thanks: 10
Scottymeuk is on a distinguished road
Default Template Phraser

What is the best method for outputting templates. At the moment I have:

Template Class:

PHP Code:
function load($viewFile,$data '')
{
    
$this->templateFolder APP_PATH 'templates/' TEMPLATE '/';  
        
    if(
file_exists($this->templateFolder '/views/' $viewFile '.php'))
    {
        
$file_output file_get_contents($this->templateFolder '/views/' $viewFile '.php');
        
        foreach(
$data as $key=>$val)
        {
            
$file_output str_replace('{' .$key '}',$val,$file_output);
        }
        
       echo 
$file_output;
    }

Controller:

PHP Code:
class index_controller extends controller
{
    function 
index()
    {
        
$data['welcome_message'] = 'This is the home page';
        
$this->core->template->load('account/test',$data);
    }
    
    function 
contact()
    {
        
$data['welcome_message'] = 'This is the contact page'
        
$this->core->template->load('account/test',$data);
    }

View File:

HTML Code:
{welcome_message}

That all works, but i need something a bit more advanced, where i can do things like:

HTML Code:
{if $core->user->isRegistered()}
    
    Hello {$core->user->info('username')}

{endif}
I don't want to use smarty or anything I ideally need just 1 function that will phrase it from that to real php. Does anyone know if there is a simpleish way of doing it.

Thanks in advance.
Scottymeuk is offline  
Reply With Quote