TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 01-07-2009, 11:54 PM   #1 (permalink)
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
 



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Template Class Issues WinSrev Advanced PHP Programming 20 11-04-2008 05:05 PM
Pure PHP template class. abiko Advanced PHP Programming 1 04-02-2008 05:45 PM
Template / Theme Parsing and Management TerrorRonin Advanced PHP Programming 6 03-18-2008 07:47 PM
Different style template system? Nor General 2 01-15-2008 01:10 PM
[Request tutorial] Template class Tanax Advanced PHP Programming 31 10-25-2007 06:56 PM


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

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design