Tizag Webmaster Forums  

Go Back   Tizag Webmaster Forums > Web Development > Server-Side Scripting > PHP Forum

Reply
 
Thread Tools Display Modes
  #1  
Old 04-06-2007, 08:44 PM
techietim's Avatar
techietim techietim is offline
Moderator
 
Join Date: Jul 2006
Location: Canada -- Home of Beavers and Maple Syrup
Posts: 4,664
techietim is just really nicetechietim is just really nicetechietim is just really nicetechietim is just really nice
(Class) Template

Here is a simple templating system.

Class
PHP Code:
<?php
class template{
    var 
$template = array();
    function 
set($a$b){ // Sets a template value
        
$this->template array_merge(array($a => $b), $this->template);
    }
    function 
set_r($a$b){ // Adds on to a template value
        
if(array_key_exists($a$this->template)){
            
$this->template[$a] .= $b;
        }else{
            
template::set($a$b);
        }
    }
    function 
write($w){ // Echo's a template
        
if(file_exists("./$w.tpl")){
        
$f files::read("./tpl/$w.tpl");
        
$f explode("@@"$f);
        foreach(
$f as $ba){
            if(
array_key_exists($ba$this->template)){
               
$o $o.str_replace($ba$this->template[$ba], $ba);
            }else{
               
$o $o.$ba;
            }
        }
        echo 
$o;
        }else{
            return 
false;
        }
    }
}
?>
Example: index.php
PHP Code:
<?php
/*
Class
*/
$temp = new template;
$temp->set("bob""Hello World");
$temp->write("test");
?>
Example: test.tpl
HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>@@bob@@</title>
</head>
<body>
<h1>@@bob@@</h1>
</body>
</html>
__________________
techietim - jcite
<><
Reply With Quote
Sponsored Links
  #2  
Old 04-10-2007, 01:41 AM
ultimateace ultimateace is offline
Student
 
Join Date: Feb 2007
Posts: 440
ultimateace will become famous soon enough
Do you write all of these scripts you post here??? I find it hard to believe that you do.
Reply With Quote
  #3  
Old 04-10-2007, 03:58 AM
techietim's Avatar
techietim techietim is offline
Moderator
 
Join Date: Jul 2006
Location: Canada -- Home of Beavers and Maple Syrup
Posts: 4,664
techietim is just really nicetechietim is just really nicetechietim is just really nicetechietim is just really nice
Quote:
Originally Posted by ultimateace View Post
Do you write all of these scripts you post here??? I find it hard to believe that you do.
Yup, I do.

Why do you find it hard to believe?
__________________
techietim - jcite
<><
Reply With Quote
  #4  
Old 04-10-2007, 01:26 PM
Scriptor Scriptor is offline
Graduate Student
 
Join Date: Jun 2006
Posts: 813
Scriptor is a jewel in the roughScriptor is a jewel in the roughScriptor is a jewel in the rough
I've helped him out a few times, trust me, he does make all the scripts himself.

Oh, and this is the first time I'm looking at this, wow, thought you meant some other kind of templating, not the php-related kind. Nice work, I suggest you make a simple site for this (if you haven't) and find ways to promote it. It's really simple and sleek, which are good selling points.
__________________
Tamreen/16/css-html-java-javascript-php
Please use the scales at the top of the post to say if my post has been useful or not.
jPOP - The all PHP Ajax and RIA Framework
Scriptex-Programming, PHP, and Dorsl
Reply With Quote
  #5  
Old 04-10-2007, 05:49 PM
ultimateace ultimateace is offline
Student
 
Join Date: Feb 2007
Posts: 440
ultimateace will become famous soon enough
Quote:
Originally Posted by techietim
Why do you find it hard to believe?
It is just that they are so... complicated! Where do you learn all of this, it can't be Tizag?
Reply With Quote
  #6  
Old 04-10-2007, 05:50 PM
techietim's Avatar
techietim techietim is offline
Moderator
 
Join Date: Jul 2006
Location: Canada -- Home of Beavers and Maple Syrup
Posts: 4,664
techietim is just really nicetechietim is just really nicetechietim is just really nicetechietim is just really nice
Hours of reading http://www.php.net/manual

Tizag is to baisc....Wayyyy to basic.
__________________
techietim - jcite
<><
Reply With Quote
  #7  
Old 04-10-2007, 05:52 PM
Nile's Avatar
Nile Nile is offline
Teacher
 
Join Date: Feb 2007
Posts: 1,617
Nile has a spectacular aura aboutNile has a spectacular aura about
Send a message via MSN to Nile Send a message via Yahoo to Nile
I remeber you telling us one day that tizag started you off,
then another site that helped you alot(not php.net).
__________________
Currently hiding Brian's key.
-Nile, I try to highlight my code.
([x]HTML, CSS) PHP, My[SQL], Javascript, C#, AS 3 [learning]
Reply With Quote
  #8  
Old 04-10-2007, 05:55 PM
techietim's Avatar
techietim techietim is offline
Moderator
 
Join Date: Jul 2006
Location: Canada -- Home of Beavers and Maple Syrup
Posts: 4,664
techietim is just really nicetechietim is just really nicetechietim is just really nicetechietim is just really nice
Yeah. http://www.php-mysql-tutorial.com maybe. But mostly self teaching.
__________________
techietim - jcite
<><
Reply With Quote
  #9  
Old 04-10-2007, 07:03 PM
ultimateace ultimateace is offline
Student
 
Join Date: Feb 2007
Posts: 440
ultimateace will become famous soon enough
Why did you give me negative rep for this??? I was simply asking a question!!!

Grrrrrr.....
Reply With Quote
  #10  
Old 04-10-2007, 08:03 PM
techietim's Avatar
techietim techietim is offline
Moderator
 
Join Date: Jul 2006
Location: Canada -- Home of Beavers and Maple Syrup
Posts: 4,664
techietim is just really nicetechietim is just really nicetechietim is just really nicetechietim is just really nice
What? I didn't. Sometimes people sign other peoples name when giving negative rep...stupid bastards.
__________________
techietim - jcite
<><
Reply With Quote
Reply

Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 01:09 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
© 2008, Tizag