stephenjbell

Split a list in half - dotCMS

Jun 30th, 2014
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 0.83 KB | None | 0 0
  1. ## This velocity code will take a list, and split it into two pieces, suitable for
  2. ## two columns. If the size of the list is odd, it will put the extra item into the first list.
  3.  
  4. #set($myListCount = $myList.size())
  5. #set($halfListCount = $myListCount * 0.5)
  6. #set($bigHalfCount = $math.ceil($halfListCount))
  7. #set($smallHalfCount = $math.floor($halfListCount))
  8.  
  9. <div class="oneoftwo">
  10.     <ul>
  11.         #set($lastInCol1 = $bigHalfCount - 1)
  12.         #foreach($myNumber in [0 .. $lastInCol1])
  13.             #set($con = $myList.get($myNumber))
  14.             <li><a href="$con.link">$con.shortTitle</a></li>
  15.         #end
  16.     </ul>      
  17. </div>
  18. <div class="oneoftwo">
  19.     <ul>
  20.         #set($lastInCol2 = $myListCount - 1)
  21.         #foreach($myNumber in [$bigHalfCount .. $lastInCol2])
  22.             #set($con = $myList.get($myNumber))
  23.             <li><a href="$con.link">$con.shortTitle</a></li>
  24.         #end
  25.     </ul>
  26. </div>
Advertisement
Add Comment
Please, Sign In to add comment