UtilMethods

Last Updated: Aug 18, 2023
documentation for the dotCMS Content Management System

The UtilMethods is a helper class providing many different methods for getting, evaluating, and comparing strings and a variety of other object types. Here are the helper methods of the UtilMethod class:

Before using UtilMethods, make sure you are familiar with the more standard tool set:

Date Handling: /docs/latest/date-viewtool

Arithmetic Operations: /docs/latest/mathtool

Number Methods

.mod Method

Returns the modulus remainder after the division of two numbers

    $UtilMethods.mod(20,8)

Returns: 4

For more number handling tools see the mathTool

String Methods

.isSet Method

Checks if a variable is set with a value

    $UtilMethods.isSet($string)  

Returns: true

.truncatify Method

Trims a string by passing a string and a limit. Adds an ellipse after the last word but leaves the last word complete.

    $UtilMethods.truncatify("The dog crossed the road", 10)

Returns: The dog crossed…

.contains Method

Returns boolean (true), if string value in parameter 1 contains string value in parameter 2

    $UtilMethods.contains("The dog barked at the car*,*dog")

Returns: true

.capitalize Method

Capitalizes the first letter of words in a string

    $UtilMethods.capitalize("the dog barked at the car") 

Returns: The Dog Barked At The Car

.encode Method

Encodes a string for passing parameters via a url

    $UtilMethods.encodeURL("http://somelink.html?test&testing=1")

Returns: http%3A%2F%2Fsomelink.html%3Ftest%26testing%3D1

.decode Method

Decodes a string (such as a parameter passed in a url)

    $UtilMethods.decodeURL("http%3A%2F%2Fsomelink.html%3Ftest%26testing%3D1") 

Returns: http://somelink.html?test&testing=1

.xmlEscape Method

Important to escape user input and prevent XSS attacks, especially useful to provides security when reading url parameters

    $UtilMethods.xmlEscape("somestring <script>hack attack</script>")

Returns: somestring <script>hack attack</script>

On this page

×

We Dig Feedback

Selected excerpt:

×