Metatags allow for defining your own HTML-like tags. When you define a metatag you have to provide the HTML code which it abbreviates. In fact metatags are just like block macros, but they have a nicer syntax. With metatags you can expand htp's functionality.
Metatags are defined with the def
blockdef
undef
As an example we show how to define a tag that builds a fancy horizontal rule out of several images.
![]() |
![]() |
In line 1 of the above example a new tag named imghr is defined.
The html code which implements this rule is following in lines 2-8.
between the def
and
/def
<imghr>
as in line 12 htp will replace this tag with the corresponding html
code. To make metatags available to all htp documents in your
project, place them in a common
Often you want to define tags that have an opening and a closing
variant. For this purpose you should use the blockdef
block
. Here is an example for this.
More sophisticated tags accept parameters. The
option
parameter lets multiple metatag parameters be
named and expanded inside the def
or
blockdef
block:
When you are using templates, the html should only be written by the template file. The normal htp files should just define macros that are used later in the template. So you may want to write block tags that just save the block in a macro for later use. Although this is possible with htp it is quite tricky, so here we present the way to do this:
This defines a block macro named section. This macro uses a
counter sect-ctr
that enumerates the sections. It is
increased for every section (line 3) and then the block macro name is
build from this counter. So the first section is stored in block
sect-1, the second in sect-2 and so on. The global
The tricky part is the expand
noexpand
flags in line 4 and 5. Normally when you define
a block macro the code between the start and end tag is literally
copied into the macro value. The expansion takes place when the macro
is used. In this case that doesn't make sense; all macros sect-1,
sect-2 and so on would just contain the same value, namely
<use block>
and block wouldn't be defined anymore
when the macros are finally expanded. Therefore we use expand to
expand the use tag already when sect-1 is defined.
The noexpand
attribute of the use
To close this example we show how to expand the
sect-${sect-ctr}
blocks in the template:
The
This closes our short htp tutorial. I hope you did enjoy it and see the advantages of using htp for your own projects. Please give us some feedback about this tutorial. What can be improved?
There is more documentation in this manual, see the