A minimalist html template, for creating full html pages using php and for maintaining a consistent look-and-feel across several individual pages. This template generates the header and footer.
headfoot.php is a html page generator template for php. It produces the initial html as well as the finishing html for a page, also known as "header" and "footer", or "top" and "bottom".
This software may be used as a quick way to do a "mock-up" for a web development project, or it may be used as part of a fully functional web site.
Usage is very simple: To use "headfoot.php", first download the php file. Then, include it in your project and call the function hf();.
A full html page may be created like this:
PHP code | Generated HTML code |
---|---|
<?php include_once("headfoot.php"); hf("h"); echo "hello world\n"; hf("f"); ?> |
<!DOCTYPE html> <html lang="en"> <head> <title>untitled</title> <meta http-equiv="content-type" content="text/html;charset=utf-8"> </head> <body> <h1>untitled</h1> hello world </body> </html> |
There are no limits to the complexity of pages that this small script may support as you are free to modify it to suit your particular purposes and preferences. Without further customization the script supports the following features:
The script should be called with variables. These are options that define what it will output. The full set of options for calling the script are:
hf($what, $p_title='', $meta_robots='', $meta_kwd='', $meta_desc='', $css_url='', $js_url='', $xtra='')
The first variable $what is the only required variable. It must be set to one of two values: "header", or "footer". However, there is some freedom of expression:
Valid header calls | Valid footer calls |
---|---|
hf("h"); | hf("f"); |
hf("head"); | hf("foot"); |
hf("header"); | hf("footer"); |
hf("top"); | hf("bottom"); |
hf("start"); | hf("end"); |
variable | description / example |
---|---|
$p_title | Page title and headline. Default "untitled" |
<title>$p_title</title> <h1>$p_title</h1> |
The default page title is "untitled". This title is used when the variable $p_title has not been set to a value.
The script has the following optional variables:
variable | description / example |
---|---|
$meta_robots | The "robots" META tag |
<meta name="robots" content="$meta_robots"> |
|
$meta_kwd | The "keywords" META tag |
<meta name="keywords" content="$meta_kwd"> |
|
$meta_desc | The "description" META tag |
<meta name="description" content="$meta_desc"> |
|
$css_url | URL to included stylesheet |
<link rel="stylesheet" type="text/css" media="screen" href="$css_url"> |
|
$js_url | URL to included javascript |
<script type="text/javascript" src="$js_url"> |
|
$xtra | (see below) |
If the variables above are not sufficient, you may include additional content using the optional variable $xtra. This variable simply prints out whatever content it has into the <head> section of the page.
variable | description / example |
---|---|
$xtra | An "extra" variable for what is not included in the variables above |
<base target="_blank"> <meta name="copyright" content="me"> |
Two extra variables exist. These must be set in the code, as it is little likely that they should change from one page to another. Unless you run a multi-language site of course, but then it will be easy to convert these into the passed-on type like those above.
variable | description / example |
---|---|
$pg_lang | Two-character language code for the page. Default "en" |
<html lang="$pg_lang"> |
|
$pg_charset | Character set code for the page. Default "utf-8" |
<meta http-equiv="content-type" content="text/html;charset=$pg_charset"> |
The default values are "en" and "utf-8".
Please click the "download" link below and the full script will be visible as a plain text file: "headfoot.php.txt"
headfoot.php.txt (1.7kB) (right-click the link, and choose "Save link/target as...")
IMPORTANT: After the download, rename the file to remove the appended ".txt" so that the file name becomes simply "headfoot.php". Feel free to choose any other file name than "headfoot" if that suits you better. The important thing is that the extension must be ".php"
The extra ".txt" filetype extension was added to enable you to view the source code, it will not work in PHP.