htp on-line reference: DEF, /DEF


Syntax

<DEF NAME="tagname" (OPTION="option1 (option2 ...)")>
</DEF>

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:

    <DEF NAME="CENTERED">
    <P ALIGN=CENTER>
    </DEF>

    <CENTERED>
    This text is centered.

Some metatags will require an opening and closing tag (comparable to <TITLE> and </TITLE>). In this case, two metatags must be created, the closing tag named the same as the open but preceded by a slash.

For example:

    <DEF NAME="BIGFONT">
    <FONT SIZE="+4">
    </DEF>

    <DEF NAME="/BIGFONT">
    </FONT>
    </DEF>

    <BIGFONT>Some large text</BIGFONT>

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 ALT SIZE">
    <FONT SIZE=${size}>
    <IF alt>
        <IMG SRC=${src} ALT=${alt}>
    <ELSE>
        <IMG SRC=${src}>
    </IF>
    </DEF>

    <DEF NAME="/HEADERIMG">
    </FONT>
    </DEF>

    <HEADERIMG SRC="logo.gif" SIZE="+2">
    A title
    </HEADERIMG>

    <HEADERIMG SRC="logo.gif" ALT="Our logo" SIZE="-1">
    Another title
    </HEADERIMG>

    this will fail:
    <HEADERIMG SRC="logo.gif" SIZE="+1" TEXT="Third title">
    </HEADERIMG>

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 ALT text 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. However, 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 TEXT parameter specified in the OPTION attribute.

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: DEF can be used to override standard HTML and htp tag names. This can cause much confusion and unexpected results. DEF can also be used to override its own tag name (DEF and /DEF). Because of the problems this can cause, its highly recommended to not override known tag names.

A more thorough discussion and more elaborate examples are discussed in the metatag section.


Table of Contents

htp on-line reference / http://maths.newcastle.edu.au/~rking/htp/ref/
Author: Jim Nelson / No email available
Maintainer: Robert King / robert.king@newcastle.edu.au

Copyright © 1995-96 Jim Nelson.
Permission to reproduce and distribute this hypertext document granted according to terms described in the Introduction

Last updated Mon Sep 23, 1996