ListTool

Last Updated: Feb 4, 2021
documentation for the dotCMS Content Management System

The ListTool extends java.lang.Object and is a viewtool for working with Lists and arrays in Velocity templates. It provides a method to get and set specified elements. Also provides methods to perform the following actions to Lists and arrays:

The following example shows how the ListTool is mapped in the toolbox-xml file:

 <tool>
   <key>listTool</key>
   <scope>application</scope>
   <class>org.apache.velocity.tools.generic.ListTool</class>
 </tool>

Example

  • Check if it is empty.
  • Check if it contains a certain element.
 $primes                     -> new int[] {2, 3, 5, 7}
  $listTool.size($primes)         -> 4
  $listTool.get($primes, 2)       -> 5
  $listTool.set($primes, 2, 1)    -> (primes[2] becomes 1)
  $listTool.get($primes, 2)       -> 1
  $listTool.isEmpty($primes)      -> false
  $listTool.contains($primes, 7)  -> true

As a note, to get an empty list use:

#set($myList = $contents.getEmptyList())

On this page

×

We Dig Feedback

Selected excerpt:

×