tag:help-archives.hannonhill.com,2010-02-09:/discussions/velocity-formats/12062-sorting-a-list-based-on-base-propertyCascade CMS: Discussion 2015-06-30T18:45:33Ztag:help-archives.hannonhill.com,2010-02-09:Comment/371642822015-06-18T20:04:17Z2015-06-18T20:04:17ZSorting a list based on base property<div><p>Hi,</p>
<p>The Sort Tool will only accept multiple arguments if you are
attempting to sort a map, but not an array.</p>
<p>One issue you will run into is that Velocity will generate an
ArrayList when using the <code>[1,2,3]</code> notation, so you need
to convert it to a native Array before passing it into the Sort
Tool. This still won't allow you to specify the direction; however,
so you basically need to sort and then reverse the array using a
loop. Consider the following:</p>
<pre>
<code>#set ( $list = [1,5,4,2,7] )
## Sort the list in ascending order
#set ( $list = $_SortTool.sort($list.toArray()) )
## Reverse the list by looping from size-1 to 0
#foreach ( $i in [$_MathTool.sub($list.size(),1)..0] )
$list.get($i)
#end</code>
</pre>
<p>Please let me know if you have any questions.</p>
<p>Thanks!</p></div>Ryan Griffith