Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search archives
  Advanced Search

Re: is this list live?


  • From: Stephen van Egmond <svanegmond(at)bang(dot)dhs(dot)org>
  • To: dan_wilson(at)geocities(dot)com
  • Cc: pgsql-php(at)postgresql(dot)org
  • Subject: Re: is this list live?
  • Date: Tue, 17 Oct 2000 17:48:25 -0400
  • Message-id: <20001017174824.A7939@bang.dhs.org> <text/plain>

Dan's approach reminds me of something I coded up to imitate a cool
feature they have in embperl.

It's so simple, I'll append it here.

The general idea is that you have a template in your document root:

root/_template.php

Which for instance can say things like:
	<html><head>.....body...

	include ("topnav.php"); ...

	##PART##

	... </html>

Obviously, you could have topnav .php right in root, but why not in the
subdirectories alongside the content:

root/foo/topnav.php
root/bar/topnav.php

The actual content pages:

root/foo/content.php
root/bar/content.php

only need to call one function to bring in the whole templating system.
Their topnav will come from the directory that they're in, and they
don't need to do anything except provide their exact functionality.

Usage:

  Put this in every file:
	<? include "templating.h"; template_header(); ?> -- at the top
	<? template_footer(); ?>  -- at the bottom

  Create a _template.html somewhere (perhaps the document root) that
contains at least the string ##PART## .

  Call template_include() when you want to pull in a file located
somewhere between your script and the document root.


<?
function template_header() {
	global $DOCUMENT_ROOT, $SCRIPT_FILENAME;
	global $_template_data, $_template_cut_index, $_template_search_path;

	$root_path = explode('/', $DOCUMENT_ROOT);
	$script_path = explode('/', $SCRIPT_FILENAME);

	for ($i = count($script_path)-1; $i >= count($root_path); $i--) {
		$directory = join('/',array_slice($script_path, 0, $i));
		$_template_search_path[] = $directory;
		if (file_exists($directory.'/_template.php')) {
			$fh  = fopen($directory.'/_template.php', 'r');
			while (!feof($fh)) {
				$_template_data .= fread($fh, 65536);
			}
			$_template_cut_index = strpos($_template_data,'##PART##');
			if ($_template_cut_index == 0) {
				print "Error: there's no ##PART## in $directory/_template.php";
				die;
			}
			eval ('?>'.substr($_template_data, 0, $_template_cut_index-2).'<?');
			return;
		}
	}
	print "didn't find a template<p>";
}

function template_footer() {
	global $_template_data, $_template_cut_index;
	eval ("?>".substr($_template_data, $_template_cut_index+6)."<?");
}

function template_include($file) {
	global $_template_search_path;
	foreach ($_template_search_path as $path) {
		if (file_exists($path.'/'.$file)) {
			include($path.'/'.$file);
			return;
		}
	}
}

?>

	



Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group