HTP

htp on-line reference : DEF, /DEF

Table of Contents
  Introduction
  License
  Tutorial
  Usage
  HTP Tags
    ALTTEXT
    BLOCK
    BLOCKDEF
  > DEF
    FILE
    IF
    INC
    IMG
    IMAGEURL
    OPT
    OUTPUT
    QUOTE
    SET
    UNDEF
    UNSET
    USE, $
    WHILE
    <!---
  History
  Wish list
  Bugs

syntax

<[ref]def name="tagname" [option="option1 [option2 ...]" ] [global] [expand]>
<[ref]/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:

    <[ref]def name="centered">
    <p align=center>
    <[ref]/def>

    <centered>
    This text is centered.

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:

  <[ref]def name="bigfont">
    <font size="+4">
  <[ref]/def>

  <[ref]def name="/bigfont">
    </font>
  <[ref]/def>

  <bigfont>Some large text</bigfont>

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.)

  <[ref]DEF NAME="HEADERIMG" OPTION="SRC TITLE SIZE">
    <[ref]IF size>
        <FONT SIZE=${size}>
    <[ref]/IF>
    <[ref]IMG SRC=pics/${src}>
    <[ref]USE title>
    <[ref]IF size>
        </FONT>
    <[ref]/IF>
  <[ref]/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:
  <[ref]DEF NAME="MYIMG" OPTION="SRC *">
    <[ref]IMG SRC="pics/${src}" $*>
  <[ref]/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 [ref]metatag section of the tutorial.

  page source
  htp project
  htp homepage
hosted by
SourceForge.net
HTML coding Powered by htp
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.
Copyright © 2001-2003 Jochen Hoenicke.
Permission to reproduce and distribute this hypertext document granted according to terms described in the License section.

last updated Fri Aug 31, 2007