Custom Tag Quickstart

Custom tags are a core piece of Tagneto's View Assembly tool. They allow the web developer to create tags that will do special processing on the page. Even normal HTML tags can be mapped to custom tag handlers.

Tagneto comes with a set of custom tags, as described in the Tags reference. However, you may want to do one of the following:
  1. Create a new tag that uses one or more of the built-in tag handlers
  2. Map an existing HTML/XML tag to one or more built-in tag handlers
  3. Build your own tag handler to use in a new tag or mapping an existing tag.
You can look at the Examples in the source tree to see these techniques used, and this page will try to give a quick overview of the techniques.

For any of these techniques, make sure you have already done the following:
  1. Download and and install Tagneto.
  2. Define a tagneticconfig configuration file.

Create a new tag that uses one or more of the built-in tag handlers

The most common example would be defining a tag that logically describes something in the UI, but does not map to a particular tag name, or it maps to a set of XML/HTML tags. For instance, say your application has a common UI element, a two pane frame, one pane above the other pane. You could use the built-in org.tagnetic.core.tags.define.DefineInclude tag handler class to make this easy. Here is what you would define in your tagneticconfig file:
  <tags nsprefix="mysite">
<tag name="twopaneframe" classname="org.tagnetic.core.tags.define.DefineInclude">
<attribute name="path" type="path">template/TwoPaneFrame.htmi</attribute>
<attribute name="newscope">true</attribute>
</tag>
<tag name="toppane" classname="org.tagnetic.core.tags.define.DefineInclude">
<attribute name="definetype">element</attribute>
</tag>
<tag name="bottompane" classname="org.tagnetic.core.tags.define.DefineInclude">
<attribute name="definetype">element</attribute>
</tag>
</tags>
In the template/TwoPaneFrame.htmi file, you could have the following HTML:
  <div style="background-color: yellow; padding: 5px; border: 5px dotted black">
  <view:out name="toppane">No top pane defined</view:out>
</div>
<div style="background-color: yellow; padding: 5px; border: 5px dotted black">
  <view:out name="bottompane">No bottom pane defined</view:out>
</div>
In an HTML page that uses the twoframepane element, the usage would look like:
  <mysite:twopaneframe>
<mysite:toppane>This is the <b>top</b>pane.</mysite:toppane>
<mysite:bottompane>This is the <i>bottom</i>pane.</mysite:bottompane>
</mysite:twopaneframe>
After tagneto runs, the resulting HTML would be:
  <div style="background-color: yellow; padding: 5px; border: 5px dotted black">
  This is the <b>top</b>pane.
</div>
<div style="background-color: yellow; padding: 5px; border: 5px dotted black">
  This is the <i>bottom</i>pane.
</div>
There are many built-in tags that you can leverage. See the source in:
  • tagneticcore/src/java/org/tagnetic/core/tags
  • tagneto/src/java/org/tagnetic/tagneto/tags
Many of the Examples use these tags, so you can check those out too.

Also remember you can define multiple tag handlers for a given tag. Just define multiple <tag> elements in your tagneticconfig file. The order of the <tag> elements in the tagneticconfig is the order in which the tag handlers will be applied. You can use the priority attribute on <tag> to modify this behavior. See the tagneticconfig reference for more information.

Map an existing HTML/XML tag to one or more built-in tag handlers

You can bind tag handlers for HTML or XML tags that you did not define. For instance, to remove all <blink> elements from your source, you could use the following in your targneticconfig file:
  <tags>
<tag name="blink" classname="org.tagnetic.core.tags.RemoveTag">
</tag>
</tags>
Notice the lack of the nsprefix="mysite" attribute on the <tags> element. This means these tag handlers will match any HTML tags that don't have a namespace defined on them.

The org.tagnetic.core.tags.RemoveTag tag handler will eat any tag that has it as a tag handler.

There are many built-in tags that you can leverage. See the source in tagneticcore/src/java/org/tagnetic/core/tags. Many of the Examples use these tags, so you can check those out too.

Build your own tag handler to use in a new tag or mapping an existing tag.

Define your own in a Java class that implements the org.tagnetic.core.framework.Tag interface or derives from the org.tagnetic.core.tags.TagWithDynamicAttributes class. See the built-in tag sources in:
  • tagneticcore/src/java/org/tagnetic/core/tags
  • tagneto/src/java/org/tagnetic/tagneto/tags
for examples on how to do this.

Once you have the tag handler defined you can use it as part of the <tag> elements in the tagneticconfig file.

Copyright © 2005 tagnetic.org.