Template class

Small, short code snippets that other people may find useful. Do you have a good regex that you would like to share? Share it! Even better, the code can be commented on, and improved.

Moderator: General Moderators

Post Reply
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Template class

Post by josh »

This is for nickman013, a simple template object
template.class.php

Code: Select all

class template {


	function template() {


	}
	
	function header() {
		ob_start();	
	}
	
	function footer() {
		$output = ob_get_clean();
		$this -> output($output);
	}
	
	function output($output) {
		require_once('template.php');
		echo $template;
	}
	
	

}
template.php

Code: Select all

<html>
<head><title></title></head>
<body>
<?php echo($output); ?>
</body>
</html>

usage

Code: Select all

<?php
require_once('template.class.php');
$template->header();
echo 'Hello world';
$template->footer();
?>
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

So basically you have a template page, that you can edit to change the style, like a style sheet. A page for the page content. And a footer for the ending of the page. Right?
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

A template object and a template file, the template file is all my HTML code, the template object handles all the nitty gritty and you just call the header and footer methods before and after your page's output
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

Nice. I like it. When I get more advanced with programming I am going to use somthing like this. Its easy and simple. I like it.
Post Reply