Skip to main content
A template does not always output the same thing. Three tools help you make the output depend on conditions or vary it within a loop. The two counter families differ fundamentally: you reset the DesignControl counters yourself and increment them deliberately to build conditions. The WS counters only run forward and are used for numbering.

Showing areas depending on counter values

The DesignControl counters DC-Counter1 to DC-Counter3 are at 0 on every page call. They can be incremented and reset as often as you like. The value is checked with the area tag of the same name.
There are exactly three counters. DC-Counter4 and higher return nothing.
The area tag can contain several values, separated by commas. {DC-Counter1(0,2,4)} applies for each of these three values.
There is no counterpart to _inc. The counter can only be incremented or reset to 0, not decremented and not set to a specific value. If you need that, use DC-Int1 to DC-Int3, which support _set, _add and _sub.

Example: showing the first available product list

A special list is to appear at the bottom of the product detail view. The first choice is Bought-Together products. If there are none, accessory products should appear, and if those are missing too, complementary products. Exactly one of the three lists should be shown in the end. The counter keeps track of whether something has already been output.
The last block no longer increments the counter. This is not an oversight: it is not queried afterwards. If you later add a fourth list, you must add the ~DC-Counter1_inc~ there.
The ~DC-Counter1_inc~ belongs inside the bracketing but before the data loop. If it is inside the loop, it counts up once per product, and the counter ends up at 5 instead of 1. For a simple check for 0 this makes no difference, but for any more precise check it does.
Reference: DC-Counter1…3 · DC-Counter1…3_inc · DC-Counter1…3_reset · CAT-AdvData() · PR-Data Guide: Displaying Bought-Together products

Numbering elements in loops

Within a loop, each element often needs its own number, for example for a unique HTML ID or for alternating class names. There are two independent counters for this. Both are at 0 on every page call and can only be incremented, not reset. This means they deliver unique numbers across an entire page.
WS-Counter and WS-Counter2 are two separate counters. You can use both at the same time on the same page without them interfering with each other.

Sequential numbering

A gallery view should give each tile its own class so that, for example, the third column can be addressed differently.
This results in category_box_1, category_box_2, category_box_3 and so on.

Unique IDs

An ID may only appear once on a page. In a loop over grouping products, the counter creates a separate ID for each form.
Note the difference in this example: the ID on the form uses WS-CounterInc and thus increments the counter. The call further down uses WS-Counter and only reads it. If WS-CounterInc were used there as well, the script would address a form that does not exist.

Alternating numbering with modulo

WS-Counter2 and WS-Counter2Inc accept a number as an argument. In that case, not the counter value is output, but its remainder when divided by this number.
This alternately results in category_td_1 and category_td_2, i.e. a color change from row to row.
The value range is between 1 and the argument, both inclusive. WS-Counter2Inc(3) therefore returns 1, 2, 3, 1, 2, 3 and never 0. This differs from the usual modulo calculation, which would yield 0 to 2, and is exactly what you need for class names.
At counter value 0, the argument returns the maximum value. ~WS-Counter2(2)~ therefore outputs 2 before the first Inc, not 0. So only read the counter after you have incremented it at least once.
Reference: WS-Counter · WS-CounterInc · WS-Counter2() · WS-Counter2Inc() Materials: Modulo calculation

Showing areas depending on strings

DC-CompareStringInList checks whether a string appears in a list of strings. Both arguments support tag-in-tag, so you can use tags instead of fixed texts. This is how a German shop shows buyers with Austria as their billing country a notice about the Austrian shop.
With several countries:
The quotation marks around the list are mandatory as soon as it contains more than one value. The tag expects exactly two parameters. Without quotation marks, the parser splits the list into individual parameters, and the tag becomes invalid.
The outer bracketing with A-CountryISO is not superfluous. It ensures that nothing is checked at all as long as the customer has not yet selected a billing country.
The tag only exists as an area tag and in the negated form. As a single tag, it returns nothing.
Reference: DC-CompareStringInList()
  • Basics: Basics of tags
  • Guide: Using free parameter tags
  • Reference: DC-Int1…3