0

In sharepoint I have created a content query webpart that queries a list and displays the title and the ImageURL field in 3 column grid format.

For some very strange reason, the code works most of the time and the image and title displays in a grid as I would like. However, if you refresh the page a few times, the image simply does not get found and inserted into the markup. The title does display all the time.

I have created my own Item Style variable in XSL itemStyles.xsl. Here is my code:

<xsl:template name="customStyle" match="Row[@Style='customStyle']" mode="itemstyle">
      <xsl:variable name="SafeLinkUrl">
          <xsl:call-template name="OuterTemplate.GetSafeLink">
              <xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
          </xsl:call-template>
      </xsl:variable>
      <xsl:variable name="SafeImageUrl">
          <xsl:call-template name="OuterTemplate.GetSafeStaticUrl">
              <xsl:with-param name="UrlColumnName" select="'ImageURL'"/>
          </xsl:call-template>
      </xsl:variable>
      <div class="item">
          <xsl:if test="string-length($SafeImageUrl) != 0">
                  <a href="{$SafeLinkUrl}">
                    <img class="image customstyle-img" src="{$SafeImageUrl}" title="{@ImageUrlAltText}" />
                  </a>
          </xsl:if>
      </div>
  </xsl:template>

I would be grateful if anybody could offer any suggestions.

Oliver

olv53
  • 63
  • 13
  • Hi Oliver, once page is rendered,using developer tool check if url is blank or url contains some garbage characters somewhere at the beginning. – Vaibhav Mar 29 '17 at 13:34
  • This is the output it creates. The url is black (ie there is not image tag created):
  • Visible Name
  • – olv53 Mar 29 '17 at 15:42
  • This is the output when the image displays correctly:
  • Name
  • – olv53 Mar 29 '17 at 15:51
  • There doesn't seem to be any garbage characters in the image url, looks pretty standard to me... – olv53 Mar 29 '17 at 15:54
  • I missed out on the part "the code works most of the time". This is strange behavior. There are few things you can try.. 1. Remove rest of the tags and only load image URLs and see if it works correctly. 2. Once you are able to load image urls successfully.. try to load them inside image tag and see it works on every page load.. 3. Try deleting browser cache once.. You never know :D – Vaibhav Mar 30 '17 at 06:09
  • Thanks, I tried removing the anchor tag it is wrapped in, and the conditional statement that tests if the string is not 0. I also just removed everything else except the outer template tag but got an error message. But no luck. Is the source of the image important? I think 'ImageURL' is a hyperlink field, should it be something else? – olv53 Mar 30 '17 at 11:47
  • When I worked on CQWP last time, If your column type is hyperlink/image, it renders with image url with some html tags. so what I want you to test is : try to print image column as simple text
    . So you will be able to find out if its bringing extra html tags along with image url with developer tools.
    – Vaibhav Mar 31 '17 at 06:44
  • Thanks, I tried this:
    and it printed the image url twice (comma separated):
    https://address.com/teams/department/team/Media%20Library/Images/Profile%20pictures/MyProfilePic.jpg, https://address.com/teams/department/team/Media%20Library/Images/Profile%20pictures/TheProfilePic.jpg
    – olv53 Mar 31 '17 at 09:37
  • Try this : – Vaibhav Apr 02 '17 at 19:29
  • Thanks, that did make it so it only prints the url once. However, it still does not retrieve the url on every page refresh.. – olv53 Apr 03 '17 at 11:04
  • Finally, I got it to work (i think) using the following code: – olv53 Apr 03 '17 at 11:41
  • How important is the {$SafeLinkUrl} variable for security? Because this seems to break it when I try and use that instead of @ImageURL... many thanks anyway – olv53 Apr 03 '17 at 11:43
  • I have never used safelinkurl ever. May be it will be useful for me in future :). I am glad it helped.. You can mark it as answered.. – Vaibhav Apr 03 '17 at 13:33