View Helpers
simpleFormat()
Signature
Section titled “Signature”simpleFormat() — returns string
Available in: controller
Category: Miscellaneous Functions
Description
Section titled “Description”Returns formatted text using HTML break tags () and HTML paragraph elements (
text that is passed in.
Parameters
Section titled “Parameters”| Name | Type | Required | Default | Description |
|---|---|---|---|---|
text | string | yes | — | The text to format. |
wrap | boolean | no | true | Set to true to wrap the result in a paragraph HTML element. |
encode | boolean | no | true | Use this argument to decide whether the output of the function should be encoded in order to prevent Cross Site Scripting (XSS) attacks. Set it to true to encode all relevant output for the specific HTML element in question (e.g. tag content, attribute values, and URLs). For HTML elements that have both tag content and attribute values you can set this argument to attributes to only encode attribute values and not tag content. |
Examples
Section titled “Examples”// 1. Format a blog post body — newlines become <br> and blank lines become paragraph breaks
writeOutput(simpleFormat(post.bodyText));
// A single newline becomes <br>
// A blank line (two newlines) becomes </p><p>
// The result is wrapped in <p>...</p> by default
// 2. Demonstrate the HTML output with literal input
text = "I love this post!" & Chr(10) & Chr(10) & "Here's why:" & Chr(10) & "* Short" & Chr(10) & "* Succinct";
writeOutput(simpleFormat(text));
// -> <p>I love this post!</p>
//
// <p>Here's why:<br>
// * Short<br>
// * Succinct</p>
// 3. Skip the wrapping paragraph tag (wrap=false) when you are composing markup yourself
writeOutput("<div>" & simpleFormat(text=post.excerpt, wrap=false) & "</div>");
// 4. Disable XSS encoding when the text is already trusted/pre-encoded HTML
writeOutput(simpleFormat(text=post.bodyText, encode=false));