HTMLMacro for Java TM
Writing your own tag set

Implementation Version: private-20080907-1331

Sometimes, it's convenient to define a macro once and use it in multiple places. You can do this by writing a tag file. This is analogous to JSP and its tag file. A tag file is simply an XML jelly script written in a *.tag file. Suppose the following file is saved in floatingBox.tag.

<j:jelly xmlns:j="jelly:core" xmlns:d="jelly:define">
  <div style="box">
    <div>${title}</div>
    <div>
      <d:invokeBody />
    </div>
  </div>
</j:jelly>

This example can be used like this:

<html>
  <body>
    ...
    <floatingBox title="Hello">
      <span>Hello, Duke!</span>
    </floatingBox>

... which produces the following output:

<html>
  <body>
    ...
    <div style="box">
      <div>Hello</div>
      <div>
        <span>Hello, Duke!</span>
      </div>
    </div>

The attributes of the tag is available to the script as variables, and {jelly:define}invokeBody tag can be used to invoke the body of the tag. Tags can also access variables defined in its caller, just like JSP tag files.