View Helpers
autoLink()
Signature
Section titled “Signature”autoLink() — returns string
Available in: controller
Category: Link Functions
Description
Section titled “Description”Turns all URLs and email addresses into links.
Parameters
Section titled “Parameters”| Name | Type | Required | Default | Description |
|---|---|---|---|---|
text | string | yes | — | The text to create links in. |
link | string | no | all | Whether to link URLs, email addresses or both. Possible values are: all (default), URLs and emailAddresses. |
relative | boolean | no | true | Should we auto-link relative urls. |
encode | any | 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. 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."