Help - Search - Members - Calendar
Full Version: Template system
Pixel2Life Forum > Member Tutorials and Requests > Forum Tutorial Archives > PHP Tutorials
-cherries-
page.php:
CODE
<?
class page {
    var $content;
    var $title;
    var $footer;

    function init() {
        head();
        body();
        foot();
    }
    function head() {
        echo "<html>\n<head>\n<title>".$this->title."</title>\n";
        css();
        echo "\n</head>";
    }
    function css() {
        echo "<style type=\"text/css\">\n";
        echo "Put styles here!";
        echo "\n</style>";
    }
    function body() {
        echo $this->content;
    }
    function foot() {
        echo "\n".$this->footer;
    }
}
?>


index.php:
CODE
<?
include("page.php");
$page = new page();
$page->title = "KSKS";
$page->content = "asdsada";
$page->footer = ":D";
$page->init();
?>


and thats a basic template class.
I did this in a hurry because I have to go to class victory.gif
Matthew.
hmm, this is *really* a template system, well not at all tbh. A template system is one where you have template files and you replace parts of it so esstially you never have to edit the core of your site.

This is just a conveinient way of making content boxes.

Maybe ill post mine later tongue.gif / do a tut.
-cherries-
I'll do a tutorial after class.
Indigo
This is more of a script than a tutorial really. If I were a total noob (which I am), I wouldn't have understood much (which I don't tongue.gif )
Ruben K
I would recommend using HTML_Template_Sigma and HTML_Page instead, they're the best ones around
BigDog
This isn't even a tutorial! You didn't explain one thing!
-cherries-
QUOTE(BigDog @ Aug 10 2006, 04:54 PM) *
This isn't even a tutorial! You didn't explain one thing!


NO WAI!?
Because I tottally said it was a tutorial too!
OMG maybe I should have stated that this wasn't a tutorial!?
cheerio
It's a super simple template class. It's pretty easy to understand
Tirus
QUOTE(-cherries- @ Sep 4 2006, 08:09 PM) *
QUOTE(BigDog @ Aug 10 2006, 04:54 PM) *

This isn't even a tutorial! You didn't explain one thing!


NO WAI!?
Because I tottally said it was a tutorial too!
OMG maybe I should have stated that this wasn't a tutorial!?

well it is posted in the tutorials section so a little explanation couldnt hurt sleep.gif
Copernicus
Well in my opinion this is a slightly more complicated one, but still basic. Easily coded as well...

CODE
<?php

/* template "system" coded by dan lamanna (copernicus)
[url=http://danlamanna.com]http://danlamanna.com[/url] - UNTESTED SCRIPT */

class Template
    {
        var $Template;
        
            function Template($TemplateFile)
                {
                    if (!file_exists($TemplateFile))
                        {
                            echo 'Template ' . $TemplateFile . ' does not exist.';
                                exit();
                            } else {
                                $this->$Template = implode("", file($TemplateFile));
                            }
                        }
                        
                            function FixTags(array($Tags))
                                {
                                    if (sizeof($Tags) > 0)
                                        {
                                            foreach ($Tags as $Tag => $Content)
                                                {
                                                    $this->Template = str_replace("{" . $Tag . "}", $Content, $this->Template);
                                                }
                                            }
                                        }
                                        
                                            function Display()
                                                {
                                                    echo $this->Template;
                                                }
?>


Ok, this is untested remember! But to output this you would do something like this....

CODE
$Template = new Template("templatepage.tpl");
       $Template->FixTags(array(
        'tag1' => "content1",
        'tag2' => "content2"));
              $Template->Display();



Dan
smart-coder
Good tutorial cherries, the code is good but you didnt explain it, but comeon! I know your a good programmer. I've seen you on the ngbbs.
Arutha
QUOTE(Cliff @ Aug 4 2006, 01:52 PM) *
I would recommend using HTML_Template_Sigma and HTML_Page instead, they're the best ones around


personally i think smarty is a better template engine. I agree with the others its not really a tutorial and its not really the best use off OOP you would get the same result as that from a basic function.

Arutha
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.