Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Gordon Saxby 1347 posts 1608 karma points
    May 14, 2012 @ 16:18
    Gordon Saxby
    0

    Check if image exists

    Is it possible, in XSLT, to check if an image physically exists? This is just in a folder on the website, it is not in the Media Library or attached to a node.

    Or is the only option to write an XSLT extension?

  • Lee Kelleher 3945 posts 15163 karma points MVP 10x admin c-trib
    May 14, 2012 @ 16:41
    Lee Kelleher
    0

    Hi Gordon,

    Say hello again to our good friend uComponents... we have an extension in our IO methods for checking if a File (or Directory) exists:

    http://ucomponents.codeplex.com/wikipage?title=IO

    You'll need to specify the full path to the file, so we've got a Server.MapPath extension in there too.

    <xsl:if test="ucomponents.io:FileExists(ucomponents.io:GetServerMapPath(umbracoFile))">

    Cheers, Lee.

  • Gordon Saxby 1347 posts 1608 karma points
    May 14, 2012 @ 17:17
    Gordon Saxby
    0

    OK - I added this to 

     <ext assembly="uComponents.Core" type="uComponents.Core.XsltExtensions.IO" alias="ucomponents.io" />
    

    xsltExtension.config.

    I added 

     xmlns:ucomponents.io="urn:ucomponents.io"

    to the XSLT, as well as 

    ucomponents.io
    

    to the exclusions list.

    I then added an IF like this 

    <xsl:if test="ucomponents.io:FileExists(ucomponents.io:GetServerMapPath($img1))">
    

    where $img1 is something like "/folder/imagename.jpg"

    but it doesn't work? It thinks the image is there, but it most definitely isn't.


  • Lee Kelleher 3945 posts 15163 karma points MVP 10x admin c-trib
    May 14, 2012 @ 17:33
    Lee Kelleher
    0

    Hi Gordon,

    Ran a test on my dev install... which *appears* to be working fine... (I literally copy-n-pasted your IF query).

    Wondering where the value of "$img1" comes from? Is it a property or string built up from elsewhere?

    Is "/folder/imagename.jpg" an accurate example? Does it definitely have a leading slash?

    Thanks, Lee.

  • Gordon Saxby 1347 posts 1608 karma points
    May 14, 2012 @ 18:03
    Gordon Saxby
    0

    Umm, odd! I made a change to test the value of the $img1 variable and now it works ... !?!

     

  • Lee Kelleher 3945 posts 15163 karma points MVP 10x admin c-trib
    May 14, 2012 @ 18:08
    Lee Kelleher
    0

    Curious how/why the test would change the outcome... Still glad that you got it working!

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies