Instead of having the header and footer in separate files as in the previous section, it is often more convenient to have them in a single file, which is a template from which the web pages are produced.
Such a template would look as follows. Click here to download tut3.htt.
Navigation bar Main Example |
The contents have to be stored into the macro body and are inserted in
line 11. To define a macro whose contents span multiple lines you can
use the
As you can see the file contains almost only the contents.
In line 1 you can see yet another syntax of the
You can see the strength of this template mechanism if you compare this reference manual with the previous at . As you can see the layout changed drastically, however, this was achieved by changing only a single file, the template file.
Of course, you can have more than one place in your template where macros are expanded. Here is an example that displays informations about employees in a common layout. For each employee you have a htp file, which just defines the personal informations in several macros, and a single template file, that lays out the informations:
Room: | |
Phone: | |
Fax: | |
Email: |
This example shows, that you can mix includes and templates. In
this case the template includes a common header and footer, which may
be shared with several templates. In line 6 and several other you can
see the
i
is used as counter variable. In line 5 it is
initialized to one. The while loop in lines 6-9 is repeatly executed
until the macro para$i
is no longer defined. It
creates a list item, prints out the section number, then a link to
#sec$i
on the current page, and writes out the title of
the section. In line 8 the macro i
is incremented. An
analogous mechanism is used to include the sections in lines 14-19.
This closes our introduction to templates. In the next section you will find some hints how you can organize your htp projects