Defining a Unique Namespace Token Using Adaptive Tags
It is an established best practice to include the pagelet/portlet
ID in the name of any Javascript functions and HTML elements to ensure
unique names when the code is combined with markup from other pagelets/portlets on an aggregated page.
The
pt:common.namespace tag allows you
to define your own token, which is replaced with the pagelet/portlet
ID. The token must follow these specifications:
- Valid values for the token must be in the ASCII range 0x21 to
0x7E, excluding "<" (0x3C).
- The scope of the token runs from the tag defining it to the end
of the file; you cannot use a token prior to defining it.
- A second pt:namespace tag with a different token redefines it;
two tokens cannot be defined at the same time.
<pt:common.namespace pt:token="$$TOKEN$$" xmlns:pt='http://www.plumtree.com/xmlschemas/ptui/'/>
<a onclick="doStuff$$TOKEN$$();" href="#">do stuff</a>
<script>
function doStuff$$TOKEN$$() {
alert("hello");
}
</script>