View Helpers
imageTag()
Signature
Section titled “Signature”imageTag() — returns string
Available in: controller
Category: Asset Functions
Description
Section titled “Description”Returns an img tag.
If the image is stored in the local images folder, the tag will also set the width, height, and alt attributes for you.
You can pass any additional arguments (e.g. class, rel, id), and the generated tag will also include those values as HTML attributes.
Parameters
Section titled “Parameters”| Name | Type | Required | Default | Description |
|---|---|---|---|---|
source | string | yes | — | The file name of the image if it’s available in the local file system (i.e. ColdFusion will be able to access it). Provide the full URL if the image is on a remote server. |
onlyPath | boolean | no | true | |
host | string | no | — | |
protocol | string | no | — | |
port | numeric | no | 0 | |
encode | boolean | no | true | Encode 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. |
required | boolean | no | true |
Examples
Section titled “Examples”1. Outputs an `img` tag for `public/images/logo.png`
#imageTag("logo.png")#
2. Outputs an `img` tag for `http://cfwheels.org/images/logo.png`
#imageTag(source="http://cfwheels.org/images/logo.png", alt="ColdFusion on Wheels")#
3. Outputs an `img` tag with the `class` attribute set
#imageTag(source="logo.png", class="logo")#
4. With explicit host and protocol
#imageTag(source="logo.png", onlyPath=false, host="cdn.myapp.com", protocol="https")#