Useful Velocity Methods

Last Updated: Feb 1, 2022
documentation for the dotCMS Content Management System
isSet() Field is set
.contains() - Field contains value: (used with check boxes, radio boxes and drop downs. These add a comma to the content so you can't use .equals() )
.equals() With string values:
With variables:
Request Parameter- This will get the value of id, if it is passed in via url or a post
Count in a loop:
This variable is updated automatically in the for-loops, it starts with value: 1 Check if equals to value:
  #if($velocityCount == 1)
Date Format: Month:
  $date.format('MMMM', $
  $date.format('yyyy', $
$date.format('MM/dd/yyyy', $content.endSeason)
  #set($dateYear = $date.get('yyyy'))
  #set($nextYear = $webapi.parseInt($dateYear) + 1)  //returns current year+1
Another formatting for date:
  $UtilMethods.dateToHTMLDate($content.gameDatetime.toString(),'EEE MMM dd hh:mm:ss z yyyy','M/d/yyyy') Eg: 7/6/2006
  $UtilMethods.dateToHTMLDate($content.gameDatetime.toString(),'EEE MMM dd hh:mm:ss z yyyy','hh:mm:ss a') Eg: 11:30 AM
Empty Container
List Size() -Can be used to determine if a pullContent query brought any results..
  #if($list.size() > 0)
.findFolder() - Returns Folder where link was created:
with a variable:
Random Generator: (usually we have a query first that pulls so many items , eg: 5, then we use the generator to randomly pick one )
  #set($list = $utilMethods.randomList($list,1))
  #set($content = $list.get($math.toInteger(0)))
If selecting only one random item, then we don't need to loop through the list- we can use $content.variable Replace String
  $string2=$string1.replaceAll("/", "//")  - replaces all / with //
String: Substring and Index of..
  $VTLSERVLET_URI.substring(0, $VTLSERVLET_URI.indexOf('/',1))
  $VTLSERVLET_URI.indexOf('/',1))  we start looking for / from the position 1 not including the character in 0
Phone Formatter:

On this page


We Dig Feedback

Selected excerpt: