Skip to content

View Helpers

simpleFormat()

simpleFormat() — returns string

Available in: controller Category: Miscellaneous Functions

Takes plain text and converts newline and carriage return characters into HTML <br> and <p> tags for display in a browser. This is particularly useful for rendering user-submitted text (like blog posts, comments, or descriptions) in a way that respects the author’s formatting. By default, the text is wrapped in a <p> element and URL parameters are encoded for safety.

NameTypeRequiredDefaultDescription
textstringyesThe text to format.
wrapbooleannotrueSet to true to wrap the result in a paragraph HTML element.
encodebooleannotrueEncode URL parameters using EncodeForURL(). Please note that this does not make the string safe for placement in HTML attributes, for that you need to wrap the result in EncodeForHtmlAttribute() or use linkTo(), startFormTag() etc instead.
1. Typical usage
#simpleFormat(post.bodyText)#

If post.bodyText =
This is the first line.

This is the second paragraph.

Output:

<p>This is the first line.</p>
<p>This is the second paragraph.</p>

2. Demonstrating line breaks
<cfsavecontent variable="comment">
I love this post!

Here's why:
* Short
* Succinct
* Awesome
</cfsavecontent>

#simpleFormat(comment)#

Output:

<p>I love this post!</p>
<p>Here's why:<br>
* Short<br>
* Succinct<br>
* Awesome</p>

3. Disable paragraph wrapping
<cfsavecontent variable="bio">
Hello, I’m Salman.
I write about ColdFusion and backend development.
</cfsavecontent>

#simpleFormat(bio, wrap=false)#

Output:

Hello, I’m Salman.<br>
I write about ColdFusion and backend development.

//No <p> tags, only <br> for newlines.

4. Handling user input safely
When you’re rendering user-submitted text in HTML attributes, simpleFormat() alone is not enough:

<!-- Incorrect usage in an attribute -->
<div title="#simpleFormat(userInput)#">...</div>

Instead, combine with EncodeForHtmlAttribute():

<div title="#EncodeForHtmlAttribute(simpleFormat(userInput))#">...</div>