Skip to content

Global Helpers

excerpt()

excerpt() — returns string

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

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.

NameTypeRequiredDefaultDescription
textstringyesThe text to extract an excerpt from.
phrasestringyesThe phrase to extract.
radiusnumericno100Number of characters to extract surrounding the phrase.
excerptStringstringno...String to replace first and / or last characters with.
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.