From: Stephen van Egmond <svanegmond@bang.dhs.org>
To: dan_wilson@geocities.com
Cc: pgsql-php@postgresql.org
Subject: Re: is this list live?
Date: Tue, 17 Oct 2000 17:48:25 -0400
Message-ID: <20001017174824.A7939@bang.dhs.org> (raw)
In-Reply-To: <20001017210903.89208.qmail@web9505.mail.yahoo.com>
References: <20001017210903.89208.qmail@web9505.mail.yahoo.com>
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;
}
}
}
?>
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-php@postgresql.org
Cc: svanegmond@bang.dhs.org, dan_wilson@geocities.com
Subject: Re: is this list live?
In-Reply-To: <20001017174824.A7939@bang.dhs.org>
References: <20001017210903.89208.qmail@web9505.mail.yahoo.com> <20001017174824.A7939@bang.dhs.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox