Alternator Viewtool documentation for the dotCMS Content Management System

Utility class for easily alternating over values in a list.

Mapping in Toolbox.xml: Alternator

The following example shows how the Alternator Viewtool is mapped in the toolbox.xml file:


Example Usage:

      String[] myColors = new String[]{"red", "blue"};
      context.put("color", new Alternator(myColors));
      String[] myStyles = new String[]{"hip", "fly", "groovy"};
      // demonstrate manual alternation with this one
      context.put("style", new Alternator(false, myStyles));

      #foreach( $foo in [1..5] )
       $foo is $color and $

      1 is red and hip
      2 is blue and fly 
      3 is red and groovy
      4 is blue and hip 
      5 is red and fly

For more information, please review our javadoc on the Alternator Viewtool