[geeks] using script to generate files from a template

Bill Bradford mrbill at mrbill.net
Sun Jun 16 05:24:44 CDT 2002


On Sun, Jun 16, 2002 at 12:03:14PM +0200, William S. wrote:
> Can anyone suggest a script that will enable me to generate
> multiple files based on a template? Each file would have a different
> filename designated in a list and insert specific strings into
> each file. For example:

Look at using PHP functions.  Here's kinda how I do a lot of the SunHELP
stuff.  

Here's the main index.php for the site:


<?
        include ( 'backend/makepage.inc');
        makepage(
		'news',
		'news',
		'xml/news.php'
		);
?>

it does:

1. includes the "makepage.inc" file, which is a (large) file that 
   defines a function makepage(). 
2. calls the makepage() function and passes it three values:
   1. HTML page title
   2. "blue bar" page title
   3. Name of actual HTML (or XML/PHP stub) to include for the page content

Here's the "makepage.inc" file, slightly edited (you can see where I insert
the variables that were passed to the function).  To add a new page to the
site, I simply make a new <pagename>.php file, edit those three parameters,
then create the .html file that goes in it.  Allows me to change the entire
site look by editing the makepage.inc file.


<?php
	function makepage($title,$header,$file)
	{
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head>

<?
require('backend/meta.inc');
require('backend/sunhelp.css');
echo "<title> SunHELP : $title </title>";
?>

</head>
<body>
<center>

<? require('backend/header.html'); ?>

<table cellspacing="2" cellpadding="2" width="98%" border="0">
<tr>
<td valign="top" align="left" width="83%" bgcolor="#666699">
<div class="bigger">

<? echo "$title"; ?>

</div></td><td valign="top" align="left" width="15%" bgcolor="#666699">
<div class="bigger">directory</div></td>
</tr>
<tr><td bgcolor="#ffffff" valign="top"><div class="page">

<? require($file); ?>

</div></td><td bgcolor="#f1f1f1" valign="top"><div class="page">

<? require("content/sitedir.html"); ?>

</div></td></tr></table>

<? require('backend/footer.html'); ?>

</center></body></html>

<? } ?>

-- 
Bill Bradford     
mrbill at mrbill.net 
Austin, TX        



More information about the geeks mailing list