Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
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?
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.
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.
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.
Umm, odd! I made a change to test the value of the $img1 variable and now it works ... !?!
Curious how/why the test would change the outcome... Still glad that you got it working!
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
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?
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.
Cheers, Lee.
OK - I added this to
xsltExtension.config.
I added
to the XSLT, as well as
ucomponents.io
to the exclusions list.
I then added an IF like this
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.
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.
Umm, odd! I made a change to test the value of the $img1 variable and now it works ... !?!
Curious how/why the test would change the outcome... Still glad that you got it working!
is working on a reply...