Skip to content

Global Helpers

truncate()

truncate() — returns string

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

Shortens a given text string to a specified length and appends a replacement string (by default ”…”) at the end to indicate truncation. It is useful for displaying previews of longer text in UIs, summaries, or reports while keeping the output concise.

NameTypeRequiredDefaultDescription
textstringyesThe text to truncate.
lengthnumericno30Length to truncate the text to.
truncateStringstringno...String to replace the last characters with.
1. Truncate text to 20 characters, default truncation string "..."
truncate(text="Wheels is a framework for ColdFusion", length=20)
/* Output: "Wheels is a fra..." */

2. Use a custom truncation string
truncate(text="Wheels is a framework for ColdFusion", truncateString=" (more)")
/* Output: "Wheels is a framework (more)" */

3. Short text does not get truncated
truncate(text="Short text", length=20)
/* Output: "Short text" */

4. Display in a view for previews
<p>truncate(article.content, 100)</p>