Skip to content

Global Helpers

wordTruncate()

wordTruncate() — returns string

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

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

NameTypeRequiredDefaultDescription
textstringyesThe text to truncate.
lengthnumericno5Number of words to truncate the text to.
truncateStringstringno...String to replace the last characters with.
1. Basic truncation (default truncate string "...")
wordTruncate(text="Wheels is a framework for ColdFusion", length=4)
// Output:
// Wheels is a framework...

2. Truncate with a custom string
wordTruncate(text="Wheels is a framework for ColdFusion", length=3, truncateString=" (more)")
// Output:
// Wheels is a (more)

3. Using with shorter text than length (no truncation applied)
wordTruncate(text="Hello world", length=5)
// Output:
// Hello world

4. Dynamic usage in a view
<cfoutput>
    wordTruncate(text=post.content, length=10)
</cfoutput>
// Useful for showing previews of long content while preserving word boundaries.