PTC ALD in Arbortext Styler > Components of Documents and Templates > Variables, Counters, and FISH > Numeric Counters
Numeric Counters
Before the inclusion of XML capabilities and XPath in PTC Arbortext Layout Developer, the use of numeric counters was the only way to provide context for conditional formatting. PTC Arbortext Layout Developer can set a counter value when it encounters an element, for example a section. It can test the value of the counter later to establish an element’s context, for example a section title. Although a complex process, it does use very little memory and it is very quick.
Numeric counters are often called x-counters. Before JavaScript, they were accessed using PTC Arbortext Layout Developer’s proprietary showstring language. The language used the syntax x(n), where n is the number of the counter ranging from 0 to 199. This method is no longer used as numeric counters can be accessed through JavaScript.
Numeric counters are accessed by number. There are 200 slots that can each be allocated an integer value. Each content stream being formatted has its own set of numeric counters. When content is repeated in frames (as opposed to flowing through frames), the counter values are reset each time PTC Arbortext Layout Developer encounters that content stream. The initial value for all numeric counters is 0.
Using Numeric Counters in JavaScript
In JavaScript, numeric counters are accessed through the fFormatting.counters array. For example, to set a counter to a value:
formatting.counters[50] = 200;
where the numeric counter 50 is set to a value of 200. Counter values can be incremented and decreased using the JavaScript instructions ++ and - -.
To use the next available counter, instead of a specified one, use the template variable template.nextCounter, as shown below.
Select the next available counter and set/reset its value to 0::
// Initialize the counter number if it hasn't yet been created
if (!template.myCounter) {
// Use the next available counter number
template.myCounter = template.nextCounter++;

formatting.counters[ template.myCounter ] = 0;
Increment the counter:
formatting.counters[template.myCounter] ++;
Display the current value of the counter:
It is possible to refer to a counter by name instead of number, which can provide more information about the use of the counter. Create a set of properties on the template object with the required values and ensure they are recreated each time the document is opened. For example:
template.counterNames.paragraphCount = 1;

fFormatting.counters is an array of PTC Arbortext Layout Developer’s numeric counters. The values are always the same whenever a particular part of a document is formatted.