Skip to content
Utility for creating snippets of documents on a search results page.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.



Utility for creating snippets of documents on a search results page.

Tell it how long you want your snippet to be (in characters) and what keywords to find/highlight. Pass an HTML string to the snip() function and it will return a relevant substring with keywords highlighted. It takes care of little annoyances: stripping unwanted HTML, starting and stopping at word boundaries, and adding ellipses where necessary.


	<cfset snipper = createObject("component", "TextSnipper")>
	<cfset snipper.setMaxLength(600)>    	
	<cfset snipper.setKeywords("Kobe,LeBron")>  

… Lakers G Kobe Bryant in terms of popularity in the country. Rovell: “Kobe is clearly bigger than LeBron. I’d say he’s at least two times bigger, and the reason for that is that Chinese really do respect a champion.” Rhoads: “For LeBron and Team LeBron, the ultimate objective has to be to get those rings onto LeBron’s …


  • setMaxLength() is optional. The default maxLength is 250 characters.
  • setKeywords() is optional. If no keywords are found, the first part of the text will be snipped.
  • It's chainable: #snipper.setMaxLength(300).setKeywords("foo,bar").snip()#
You can’t perform that action at this time.