HeadFoot.php : HTML page generator / template

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.

About

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

Basic use

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>
                    

Documentation

Advanced use

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:

Calling the script

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='')

 

First variable: $what (required)

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 callsValid footer calls
hf("h"); hf("f");
hf("head"); hf("foot");
hf("header"); hf("footer");
hf("top"); hf("bottom");
hf("start"); hf("end");
The "$p_title" variable
variabledescription / example
$p_titlePage 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 optional variables

The script has the following optional variables:

variabledescription / example
$meta_robotsThe "robots" META tag

<meta name="robots" content="$meta_robots">
 
$meta_kwdThe "keywords" META tag

<meta name="keywords" content="$meta_kwd">
 
$meta_descThe "description" META tag

<meta name="description" content="$meta_desc">
 
$css_urlURL to included stylesheet

<link rel="stylesheet" type="text/css" media="screen" href="$css_url">
 
$js_urlURL to included javascript

<script type="text/javascript" src="$js_url">
 
$xtra(see below)
The "$xtra" variable

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.

variabledescription / example
$xtraAn "extra" variable for what is not included in the variables above

<base target="_blank">
<meta name="copyright" content="me">
 

Extra settings

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.

variabledescription / example
$pg_langTwo-character language code for the page. Default "en"

<html lang="$pg_lang">
 
$pg_charsetCharacter 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".

Version and License

Version

Current version: 0.1

License

What? Free!

Source Code and Download

Source code

Please click the "download" link below and the full script will be visible as a plain text file: "headfoot.php.txt"

Download

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.