htp on-line reference : Templates |
||||||||
How to use templatesInstead 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. A simple exampleSuch a template would look as follows. Click here to download tut3.htt.
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 block tag. Here is the file tut3.htp that makes use of the template:
In line 1 you can see yet another syntax of the file tag. The You can see the strength of this template mechanism if you compare this reference manual with the previous at http://math.newcastle.edu.au/~rking/htp/. As you can see the layout changed drastically, however, this was achieved by changing only a single file, the template file. Including more than one piece of informationOf 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:
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 if tag. This tag can be used to check if a variable is defined or if it has a certain value. In this case the tag is used to omit information that wasn't defined for this person. How to include numbered sectionsOne feature of htp is a loop construct that enables you to create numbered sections. Here is the example for the contents file.
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
|
||||||||
|
||||||||
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. last updated Tue Apr 15, 2014 |