You are here: Reference > Streams and JSP > JavaServer Pages tags > onlyonce

onlyonce JavaServer Page tag

Use the onlyonce JSP tag to indicate that text within the body of the tag is to be included in the stream processing output only the first time that an onlyonce tag of that name is found.

This tag is primarily useful in complex HTML streams to prevent multiple definitions of JavaScript functions.

When to use

When entering HTML source code directly into the HTML tab of a control rule (or similar form), you can minimize the size of the resulting HTML document with the <pega:onlyonce > and <pega:static > tags. See Including only one copy of JavaScript code in More about control rules.

Example

For example, this tag is named Alpha.

<!-- define scripts -->
<pega:onlyonce name="Alpha" >
The work item id is <pega:reference name=".pyID">
</pega:onlyonce >

During stream processing, if another onlyonce tag named Alpha appears, the body of the second (and later) tags are skipped over and not processed.

Complete syntax

In the syntax presentations below:

<pega:onlyonce name="name" >
HTML, XML or JavaScript code to process only once
</pega:onlyonce >

The name attribute is required.

Attribute

Description

name

Set the name attribute to an arbitrary non-blank text value. Case is significant. During stream processing, second and later appearances of an onlyonce tag with this name cause the body of the tag to be treated as a comment, contributing nothing to the stream results.

JavaServer Page Tags