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: 2000-10-17 21:48:25
Message-ID: 20001017174824.A7939@bang.dhs.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-php

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;
}
}
}

?>

In response to

Browse pgsql-php by date

  From Date Subject
Next Message Chris 2000-10-18 10:45:58 files, php & pgsql
Previous Message Dan Wilson 2000-10-17 21:09:03 Re: is this list live?