# htp on-line reference : DEF, /DEF

## syntax

`<set time="0">
<block name=a>
a is expanded at time <use time>.
</block>
<block name=b expand>
b is expanded at time <use time>.
</block>
<set time="1">
<use a>
<use b>
contents of a: <use a noexpand>
contents of b: <use b noexpand>
<block name=c expand>
c is expanded at time <use time>; <use a>
</block>
<block name=d expand>
d is expanded at time <use time>; <use a noexpand>
</block>
<block name=e>
e is expanded at time <use time>; <use a noexpand>
</block>
<set time="2">
<block name=a>
a is defined for the 2nd time <use time>.
</block>
<use c>
<use d>
<use e>
`

## synopsis

DEF creates metatags, which is a fancy way of saying it creates new tags. The mechanism is very similar to BLOCK macros, except that the USE tag is not used to expand them. Instead, they are expanded by their own name. For example:

`<if disabled_because_xyz>
...
</if>
`

Some metatags will require an opening and closing tag (comparable to and ). In this case, you should use the BLOCKDEF macro. Another slightly faster alternative is to use two metatags, the opening tag and the closing tag with a preceding slash. For example:

`<EM>File "<FILE NAME>" last updated <FILE TIME>, <FILE DATE></EM>
`

You should really use BLOCKDEF, though, as it will check for matching end tag. It is not that slower.

Options can be passed to a metatag, which can then expand as if it were a SET macro. Option names are parameterized with the OPTION attribute. Multiple options can be listed by separating their name with a space (which therefore requires they be surrounded by quotes.)

`<img src="filename" ...>
`

htp will do very specific checking of parameters when a metatag is invoked. htp assumes that all parameter options to the metatag are optional. This is why the HEADERIMG definition uses IF to verify the SIZE option is defined before expanding it in the block. If a parameter is required, simply expand it without first checking. When htp expands the metatag and the macro is not defined, it will halt processing and complain with an error message and the required macro name. Normally htp will not allow parameters not listed in the OPTION attribute to be added to the tag. This is why the third invocation of HEADERIMG will fail. There is no ALT parameter specified in the OPTION attribute. However, there is the special option *, which matches every other parameter. It should be used to pass all other options to another tag.

Metatags can be removed by using the UNDEF tag. Note that both open and close tags must be removed with UNDEF. Removing one will not remove both.

Warning: Although possible, `def` should not be used to override standard HTML and htp tag names, as this can cause much confusion and unexpected results. The `def` tag can even be used to override its own tag name. Because of the problems this can cause, its highly recommended to not override known tag names.

You can find some other examples in the metatag section of the tutorial.

hosted by Sourceforge HTML coding

Copyright © 1995–96 Jim Nelson. Copyright © 2001–2014 Jochen Hoenicke. Permission to reproduce and distribute this hypertext document granted according to terms described in the License section. last updated Sat May 16, 2015