Global Helpers
wordTruncate()
Signature
Section titled “Signature”wordTruncate() — returns string
Available in: controller, model, test, migrator, migration, tabledefinition
Category: String Functions
Description
Section titled “Description”Truncates text to the specified length of words and replaces the remaining characters with the specified truncate string (which defaults to ”…”).
Parameters
Section titled “Parameters”| Name | Type | Required | Default | Description |
|---|---|---|---|---|
text | string | yes | — | The text to truncate. |
length | numeric | no | 5 | Number of words to truncate the text to. |
truncateString | string | no | ... | String to replace the last characters with. |
Examples
Section titled “Examples”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.