Skip to content

View Helpers

autoLink()

autoLink() — returns string

Available in: controller Category: Link Functions

Turns all URLs and email addresses into links.

NameTypeRequiredDefaultDescription
textstringyes—The text to create links in.
linkstringnoallWhether to link URLs, email addresses or both. Possible values are: all (default), URLs and emailAddresses.
relativebooleannotrueShould we auto-link relative urls.
encodeanynotrueUse 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.
// 1. Link both URLs and email addresses (default behavior)
result = autoLink("Download CFWheels from http://cfwheels.org/download");
// result -> "Download CFWheels from <a href="http://cfwheels.org/download">http://cfwheels.org/download</a>"

// 2. Link email addresses only
result = autoLink(text="Email us at info@cfwheels.org or visit http://cfwheels.org", link="emailAddresses");
// result -> "Email us at <a href="mailto:info@cfwheels.org">info@cfwheels.org</a> or visit http://cfwheels.org"

// 3. Link URLs only (skip email addresses)
result = autoLink(text="Visit http://cfwheels.org or contact info@cfwheels.org", link="URLs");
// result -> "Visit <a href="http://cfwheels.org">http://cfwheels.org</a> or contact info@cfwheels.org"

// 4. Disable auto-linking of relative URLs
result = autoLink(text="See /docs/guide for details or http://cfwheels.org for more.", relative=false);
// result -> "See /docs/guide for details or <a href="http://cfwheels.org">http://cfwheels.org</a> for more."