Skip to main content
Known Participant
August 14, 2008
Question

cfif not exists

  • August 14, 2008
  • 2 replies
  • 478 views
Hi.what would be the code look like when I want to say type no image when there is no image on the images folder?
this one didnt work:

<cfif isDefined("getBrands.cat_level2_image")><img src="#imagePath#images/logoImages/#getBrands.cat_level2_image#" /></a><cfelse>No Image</cfif>
This topic has been closed for replies.

2 replies

Inspiring
August 15, 2008
a few suggestions:

1) drop the # inside the <cfif ...> - no need for them there.
2) better checking may be <cfif len(trim(getBrands.cat_level2_image))>
3) you may also want to check that the image file exists in that folder:
<cfif len(trim(getBrands.cat_level2_image)) AND
fileexists(expandpath('#imagePath#images/logoImages/#getBrands.cat_level2_image#'))>
- this way you won;t get the broken image/red cross icon if the redord
for the image in your db exists but the actual image in the folder has
been deleted...
4) alternative to #3 is adding an onError event to the <img> tag with a
simple js changing the image source to some generic "No Image Available"
image: <img src="..." ... onError="this.src='your_no_image_available.jpg';">

hth


Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
Known Participant
August 14, 2008
I found my mistake:

<CFIF #getBrands.cat_level2_image# EQ "">
<img src="#imagePath#images/logoImages/#getBrands.cat_level2_image#" width="60" height="40" border="0" alt="#getBrands.cat_level2_name#" hspace="2" /></a><cfelse>No Image Available </cfif>

:)