HTP

htp on-line reference : Macros

Table of Contents
  Introduction
  License
  Tutorial
  > Macros
    Including
    Templates
    Files
    Metatags
  Usage
  HTP Tags
  History
  Wish list
  Bugs

The Tutorial

This tutorial should help you with the first steps in htp. This tutorial assumes that you are already somewhat familiar with HTML. You can find good HTML tutorials on the web, e.g. at the W3Schools. If you speak german, spanish, french or japanese, you should take a look at SELFHTML.

On this and the following pages we want to give you an idea of how htp is used. If you read this the first time you should not follow the links to the [ref]reference manual.

Writing simple htp files

In their simplest form htp files are just ordinary html files. In that case the htp process just copies the file. However, there are some features of htp makes live easier in many cases. Let's have a look at a simple example:

 1. <[ref]set author="Joe Doe">
 2. <[ref]set email="webmaster@domain.com">
 3.
 4. <html>
 5. <head>
 6.   <meta name="author" content="$author">
 7.   <title>My first htp page</title>
 8. </head>
 9. <body>
10. This page was produced by htp.
11. <hr>
12. Copyright by <[ref]use author>,
13. <a href="mailto:$email"><[ref]use email></a>,
14. last updated <[ref]file date>
15. </body>

You can download the file tut1.htp and put it into an empty directory. Then you can invoke htp from the command line (e.g. from the DOS box) like this:

htp tut1.htp tut1.html
This creates a file tut1.html, your first html file produced by htp.

In line 1 we use a special tag named [ref]set. Even though this looks like a html tag it is really a htp tag. htp reads this but it doesn't copy it over in the html file. Instead it defines the macro author and bind the value Joe Doe to it. This macro is later expanded in line 6 and line 12, to retrieve the author name again.

The advantage of using macros is obvious if you consider the email macro in line 2 and 13. Normally you need to type the email twice, once in the href attribute and once to show up on the page. If you have a typo in the href tag you probably won't notice it. With the use of macros you only have to type the email once. Also you have to update only one place when your email address changes.

As you can see there are two ways to get the value, which is bound to a macro: One is the [ref]use tag in line 12. This tag is replaced by htp with the contents of the macro, Joe Doe in this case. However, if the macro needs to be expanded inside an html or htp tag, you can't nest a [ref]use tag. Instead the "$" character followed by the macro name can be used as shown in lines 6 and 13.

In line 14 you can see another special htp tag, the [ref]file tag. This tag has many functions, however, in this case it is just used to get the modification date of the current htp file.

In the next section of this tutorial we show you how to use htp in big projects where you have many web pages that should get a similar layout.

Go to the next section

  page source
  htp project
  htp homepage
hosted by
SourceForge.net
HTML coding Powered by htp
htp on-line reference / http://htp.sourceforge.net/ref/
Authors: Jim Nelson, Jochen Hoenicke, Michael Möller.
Maintainers: Jochen Hoenicke.

Copyright © 1995-96 Jim Nelson.
Copyright © 2001-2003 Jochen Hoenicke.
Permission to reproduce and distribute this hypertext document granted according to terms described in the License section.

last updated Tue Apr 15, 2014