htp on-line reference: Templates

htp allows for templates to be used, where one file defines a standard layout scheme that can be reused for any number of documents. Templates are not a feature per se, but is available by utilizing several of htp's features.

Below is a simple htp template file. The tags are hyperlinked for convenience.


<IF title>
<SET pagetitle=$title>
<SET pagetitle="Default title">


<USE pagetitle>


<USE pagetitle>


<USE body>



The first tag, OPT, sets options that are used for the rest of the document. The second block of tags, defining the pagetitle macro, is used to set a default title if one is not supplied by the master document. This technique can also be used to give a set of pages a common title "prefix." For example, all page's titles in this reference start with the string "htp on-line reference".

The only other macro that must be defined by the page is the body variable (not to be confused with the HTML BODY markup tag). The text defined in the body macro is expanded inside the tag, surrounded by rulings.

So, a simple document could do this:

<FILE TEMPLATE="template.htt">

<SET title="A Simple Page">

<BLOCK body>
This is some simple text that will be expanded in the BODY section of the
HTML file.

Other documents could be constructed using a similar format. When htp parses and processes the documents, they will be completely expanded and ready to be served up onto the Web.

And, since one file contains all layout information about the document, if this simple template were to be spruced up with graphics or additional formatting, only one file needs to be changed.

Templates are not only useful for defining complete documents. They can also be used for defining a small formatted portion of the HTML file. For example, if a page wanted to include a drop quote (where a short sentence is quoted in larger characters in the middle of an article), a drop quote template file could be created.

<USE dropquote>

The macro dropquote could be defined in the calling document, and the template file included at the location where the dropquote should be placed. Note that the dropquote macro can be defined and re-defined indefinitely, so a new drop quote can be placed several times in the document. And, again, if the format of the drop quote should be changed, only one file needs to be edited for the change to propogate to all documents.

Table of Contents

htp on-line reference /
Author: Jim Nelson / No email available
Maintainer: Robert King /

Copyright © 1995-96 Jim Nelson.
Permission to reproduce and distribute this hypertext document granted according to terms described in the Introduction

Last updated Fri Oct 27, 2000