Jump to content


* * * - - 5 votes

Template system


  • Please log in to reply
11 replies to this topic

#1 _*-cherries-_*

_*-cherries-_*
  • Guests

Posted 02 August 2006 - 12:24 PM

page.php:
<?
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:
<?
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 :P

#2 Matthew.

Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 02 August 2006 - 12:27 PM

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 :P / do a tut.

#3 _*-cherries-_*

_*-cherries-_*
  • Guests

Posted 02 August 2006 - 12:28 PM

I'll do a tutorial after class.

#4 Indigo

Indigo

    Official Alien

  • Members
  • PipPipPip
  • 617 posts
  • Gender:Male
  • Location:Trondheim, Norway
  • Interests:Computing in general, especially design and programming of all kinds.

Posted 03 August 2006 - 04:47 PM

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 :P )

#5 Ruben K

Ruben K

    Cliff

  • Twodded Staff
  • PipPip
  • 438 posts

Posted 04 August 2006 - 08:52 AM

I would recommend using HTML_Template_Sigma and HTML_Page instead, they're the best ones around

Edited by Cliff, 04 August 2006 - 09:01 AM.


#6 BigDog

BigDog

    Young Padawan

  • Members
  • Pip
  • 277 posts
  • Gender:Male
  • Location:Orange County, California
  • Interests:Running, building computers, PC games and BMX and programming.

Posted 10 August 2006 - 04:54 PM

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

#7 _*-cherries-_*

_*-cherries-_*
  • Guests

Posted 04 September 2006 - 07:09 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!?

#8 cheerio

cheerio

    Young Padawan

  • Members
  • Pip
  • 246 posts
  • Gender:Male

Posted 04 September 2006 - 07:18 PM

It's a super simple template class. It's pretty easy to understand

#9 Tirus

Tirus

    P2L Jedi

  • Members
  • PipPipPip
  • 764 posts
  • Gender:Male
  • Location:Montreal, Canada
  • Interests:Web Design, Programming, Music, Martial Arts

Posted 04 September 2006 - 09:25 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 ;)

#10 Copernicus

Copernicus

    Young Padawan

  • Members
  • Pip
  • 32 posts

Posted 04 September 2006 - 10:15 PM

Well in my opinion this is a slightly more complicated one, but still basic. Easily coded as well...

<?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....

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


Dan

Edited by Copernicus, 04 September 2006 - 10:16 PM.


#11 smart-coder

smart-coder

    Young Padawan

  • Members
  • Pip
  • 16 posts

Posted 29 January 2007 - 08:35 PM

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.

#12 Arutha

Arutha

    Young Padawan

  • Members
  • Pip
  • 144 posts
  • Gender:Male
  • Location:Southampton, England

Posted 19 February 2007 - 04:56 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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users