Global Helpers
excerpt()
Signature
Section titled “Signature”excerpt() — returns string
Available in: controller, model, test, migrator, migration, tabledefinition
Category: String Functions
Description
Section titled “Description”excerpt() extracts a portion of text surrounding the first instance of a given phrase. This is useful for previews, search result snippets, or highlighting context around a keyword.
Parameters
Section titled “Parameters”| Name | Type | Required | Default | Description |
|---|---|---|---|---|
text | string | yes | — | The text to extract an excerpt from. |
phrase | string | yes | — | The phrase to extract. |
radius | numeric | no | 100 | Number of characters to extract surrounding the phrase. |
excerptString | string | no | ... | String to replace first and / or last characters with. |
Examples
Section titled “Examples”Example 1 — Basic usage
<cfscript>
text = "Wheels is a Rails-like MVC framework for Adobe ColdFusion and Lucee";
snippet = excerpt(text=text, phrase="framework", radius=5);
writeOutput(snippet);
</cfscript>
Output:
... MVC framework for ...
Extracts 5 characters before and after "framework".
Adds ... at the start and end to indicate truncation.
Example 2 — Increase radius
<cfscript>
snippet = excerpt(text=text, phrase="framework", radius=20);
writeOutput(snippet);
</cfscript>
Output:
... Rails-like MVC framework for Adobe Cold...
Shows more surrounding context (20 characters before and after the phrase).
Example 3 — Custom excerpt string
<cfscript>
snippet = excerpt(
text=text,
phrase="framework",
radius=10,
excerptString="***"
);
writeOutput(snippet);
</cfscript>
Output:
*** Rails-like MVC framework for Adob ***
Uses *** instead of ... to mark truncated text.