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:
a is expanded at time 1.
b is expanded at time 0.
contents of a: a is expanded at time < use time>.
contents of b: b is expanded at time 0.
c is expanded at time 1; a is expanded at time 1.
d is expanded at time 1; a is expanded at time 2.
e is expanded at time 2; a is defined for the 2nd time < use time>.
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:
< imageurl url="http://my.domain.org/" path="/var/www/my.domain/">
< imageurl url="other.domain.org/" path="/var/www/other.domain/">
For this line: < img src="logo.gif">
the local filename "logo.gif" will be used to determine image dimensions
(no URL replacement).
For this line: < img src="http://my.domain.org/logo.gif">
the local filename "/var/www/my.domain/logo.gif" will be used.
But for this line: < img src="http://other.domain.org/logo.gif">
the local file cannot be found (no prefix match), so the image dimensions
will not be added.
Order is important; last IMAGEURL tag takes precedence:
< imageurl url="/" path="/var/www/htdocs/">
< imageurl url="/test/" path="/var/www/test/">
< img src="/image.gif"> and < img src="/test/image.gif"> are mapped to
/var/www/htdocs/image.gif and /var/www/test/image.gif, resp.
If the order of the imageurl lines would be swapped, the second
image would be mapped to /var/www/htdocs/test/image.gif.
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.)
< DEF NAME="HEADERIMG" OPTION="SRC TITLE SIZE">
< IF size>
<FONT SIZE=${size}>
< /IF>
< IMG SRC=pics/${src}>
< USE title>
< IF size>
</FONT>
< /IF>
< /DEF>
<HEADERIMG SRC="logo.gif" SIZE="+2" TITLE="A title">
<HEADERIMG SRC="logo.gif" TITLE="Normal sized title">
This will fail:
<HEADERIMG SRC="logo.gif" ALT="Our logo" TITLE="Another title">
Instead, use * like this:
< DEF NAME="MYIMG" OPTION="SRC *">
< IMG SRC="pics/${src}" $*>
< /DEF>
<MYIMG SRC="logo.gif" ALT="Our logo">
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.
|