Skip to content

Global Helpers

truncate()

truncate() — returns string

Available in: controller, model, mapper, migrator, migration, tabledefinition Category: String Functions

Truncates text to the specified length and replaces the last characters with the specified truncate string (which defaults to ”…”).

NameTypeRequiredDefaultDescription
textstringyes—The text to truncate.
lengthnumericno30Length to truncate the text to.
truncateStringstringno...String to replace the last characters with.
// 1. Truncate to a specific character length (defaults to "..." suffix)
truncated = truncate(text="CFWheels is a framework for ColdFusion", length=20);
// truncated -> "CFWheels is a fra..."

// 2. Use a custom truncate string instead of the default ellipsis
truncated = truncate(text="CFWheels is a framework for ColdFusion", truncateString=" (more)");
// truncated -> "CFWheels is a framework fo (more)"

// 3. Text shorter than the length limit is returned unchanged
truncated = truncate(text="Hello", length=30);
// truncated -> "Hello"