Main ----- Copyright Up Previous Next

Macros

Macros are a powerful feature which enables you to create shortcuts for often used text. As you can also pass arguments to macros, it is even possible to create templates for whole pages.

General syntax

Macros can be defined like
<$MACRO MacroName [ modifiers ] [ attributes ] >

...macro text...

</$MACRO>
Here are some examples of macro definitions:

Use as a shortcut

You can define a macro called MyAddress that only is a shortcut for your email-address like
<$MACRO MyAddress>
hugo@some.where
</$MACRO>
So every time, you insert the macro-tag <MyAddress> in your hsc-source, it will be replaced by
hugo@some.where
in the html-object.

Create your own logical style

One of the most embarassing facts within html are physical/logical styles. Taking a look at the HTML 3.0 proposed things, you find loads of new styles: <AU> for authors, <SAMP> for sequences of litteral characters and so on... No one knows where this will end, and I'm just waiting for logical styles like <TIM_BERNERS_LEE_S_LOGICAL_STYLE_TO_RENDER_THE_NAME_OF_HIS_DOG>. (Which would asume that TBL has a dog)

Anyway, while other people think about which logical style should get his own tag and which not, you can define your own styles. For example, a logical style to render a filename could look like this:
<$MACRO FILE><I></$MACRO>      <* enable italic *>
<$MACRO /FILE></I></$MACRO>    <* disable italic *>
Your new style can be used like all other styles:
  ..open the file <FILE>hugo.txt</FILE> and..
In this case, filenames will be rendered italic:
..open the file hugo.txt and..

This seems much more reasonable to me then producing heaps of logical styles, but..

Note that you just created a container that requires a start- and end-tag.

Macros with custom attributes

Take a look at this example:
<$MACRO BUTTON_NEXT NxtRef:uri>
<A HREF=(NxtRef)><IMG SRC=":image/next.gif" ALT="Next"></A>
</$MACRO>
This defines a macro that defines a button that references to the next page. As every page has its own next page, you can set one attribute for this macro: NXTREF, which is the URI that should be referenced as the "next" page.

So an example usage of this macro would be:

  <BUTTON_NEXT NXTREF=":features/rplcent.html">
which will give the button seen below:

Next

Note that the value of NXTREF is passed to the HREF attribute within the <A> tag when the macro is extracted.

If you wonder, what HREF=(NxtRef) (see above) should mean: This sets HREF with the value stored in NxtRef. For details, read the section about expressions.

Some Notes

Macro attributes can only be defined within start-macros. The corresponding end-macro automatically inherits all attributes of its opening macro.

To make your macros more powerful and flexible, you can use expressions and conditional conversion.


Thomas Aglassinger (agi@giga.or.at), 04-Dec-1996