2 Replies Latest reply on Aug 14, 2008 10:57 PM by Newsgroup_User

    cfif not exists

    masoud_amen
      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>
        • 1. Re: cfif not exists
          masoud_amen Level 1
          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>

          :)
          • 2. Re: cfif not exists
            Level 7
            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/