Source code: ref/use.htp

Table of Contents

<block syntax>
<use macroname [parameters ...] [noexpand]>
<... $macroname ...>
<... ${macroname} ...>

<block synopsis>

<strong>USE</strong> will expand macros that have been previously
declared with either <A HREF="set.html">SET</A> or <A
BLOCK</A>.  USE can only be used outside of other
markup tags.

<p> If you USE a block macro the value of expanded block macros will
be further parsed by htp.  This is maybe not what you want, for
example, if the use is inside a block which <a
expands</a> itself. You can use the noexpand
attribute to prevent further expansion.  </p>

<p> USE will accept additional parameters, which are "local" macros
for the expanded macro.  This is only valid for <A
BLOCK</A> macros.  Macros created using <A
SET</A> cannot have parameters passed.  For

<htpcode option="-n">
<block stuff>
  <a href=$email>send email</a>

<set morestuff=$email>

This works:     <use stuff email="">
But this fails: <use email>
And this fails: <use morestuff email="">

(See below for a description of the '$' operator.)  The example on
line 7 works because "stuff" has been declared as a block macro, and
the tag is passing the "email" macro to the "stuff" macro.  Line 8
fails because the "email" macro is unavailable once the block macro is
completely expanded, and cannot be passed to a SET macro.
Note that the "email" macro is available to other macros or included
files called within the "stuff" block.
Inside a markup tag, like <a href="img.html">IMG</a>, A (anchor), or
any other standard HTML or htp tag, the '$' operator must be used.
The '$' should be immediately followed by the macro name, which may or
may not be surrounded by curly braces.  When htp encounters this it
replaces the macro name by the contents of the macro without further
processing the contents.

<htpcode option="-n">
<a href="mailto:$email">mailto hyperlink</a>
<a href="http://$domain/~${username}/">another hyperlink</a>
The use of curly braces is encouraged, since it is more robust and
should never cause confusion with surrounding text.  If no curly
braces are used the macro name consists either of a single punctuation
character or the maximum sequence of letters, digits, &quot;-&quot;
and &quot;_&quot; that follows it.
If a '$' character needs to be kept in the final output, and not
interpreted as a macro name, it must be escaped by another '$'
character.  This is especially true for PHP code.
If the '$' macro is the only text in the attribute's value, htp will
automatically surround it with quotation marks to prevent spaces from
delimiting the text as if it were additional markup attributes.
If the '$' macro is surrounded by other text (as in the two examples above),
quotation marks are not automatically supplied.
Note that a '$' macro can be placed anywhere in a markup tag and can
be nested.  This is valid:

    <${tagName} ${attrName}=${value$ctr}>

<P> The tagName macro can contain any tag name, even a self-defined
metatag.  Note that <code>$ctr</code> is expanded before the valueX
macro is expanded, so assuming that ctr was set to 1 it will expand


  page source
  htp project
  htp homepage
hosted by
HTML coding Powered by htp
htp on-line reference /
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 Tue Feb 22, 2011