Skip to content

View Helpers

imageTag()

imageTag() — returns string

Available in: controller Category: Asset Functions

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.

NameTypeRequiredDefaultDescription
sourcestringyesThe 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.
onlyPathbooleannotrue
hoststringno
protocolstringno
portnumericno0
encodebooleannotrueWhen set to true, encodes tag content, attribute values, and URLs so that Cross Site Scripting (XSS) attacks can be prevented. Set to attributes to only encode attribute values and not tag content.
<!--- Outputs an `img` tag for `images/logo.png` --->
#imageTag("logo.png")#

<!--- Outputs an `img` tag for `http://cfwheels.org/images/logo.png` --->
#imageTag(source="http://cfwheels.org/images/logo.png", alt="ColdFusion on Wheels")#

<!--- Outputs an `img` tag with the `class` attribute set --->
#imageTag(source="logo.png", class="logo")#