If there is no image uploaded to the image item the ID and standard attributes are all set but the elements like umbracofile have no value so would result in an empty src attribute in your img tag.
Does the visualiser display "The XSLT didn't generate any output" or nothing at all?
Problem with displaying images from Media library
Hi all,
I have a couple of images uploaded to the Media library, and created a document type called "Carousel" with a media picker and a multiline textbox.
Now, I'm trying to loop through all contents of type "Carousel" and display the images added to the contents.
However, although I get the ID of the image in Media library on the UI it shows just a broken image, as no image path is returned.
Here is the code:
<xsl:variable name="documentTypeAlias" select="string('Carousel')"/>
<xsl:template match="/">
<!-- The fun starts here -->
<ul>
<xsl:for-each select="$currentPage/* [name() = $documentTypeAlias and string(umbracoNaviHide) != '1']">
<li>
<xsl:value-of select="./text"/>
<xsl:variable name="sliderImage" select="./image" />
<xsl:if test="$sliderImage != ''">
<xsl:variable name="media" select="umbraco.library:GetMedia($sliderImage, 0)" />
<xsl:value-of select="$media"/>
<xsl:if test="$media">
<img src="{$media/umbracoFile}" alt="{$media/altText}" />
</xsl:if>
</xsl:if>
</li>
</xsl:for-each>
</ul>
</xsl:template>
The variable "$sliderImage" returns the ID of the image in library, but the GetMedia library returns nothing.
Can someone help, please?
Thanks
Try this:
<xsl:variable name="media" select="umbraco.library:GetMedia($sliderImage, false)" />
Strange! Does your media item actually have an image assigned to it?
What does <xsl:copy-of select="$media"/> bring back? (instead of value-of) with Encode/Decode ticked of course
What do you get if you do a:
-- Nik
Hi,
the image is assigned to the media item, otherwise it wouldn't be able to get the ID of the image in Media libraray, I believe.
The code you suggested returns nothing (empty).
I also tried to use false instead of 0 in the function, but again nothing happened. It's really strange.
Not sure what is the problem.
If there is no image uploaded to the image item the ID and standard attributes are all set but the elements like umbracofile have no value so would result in an empty src attribute in your img tag.
Does the visualiser display "The XSLT didn't generate any output" or nothing at all?
Any chance a content republish would help?
Hi,
the problem is solved. James was right. I had to upload the images again to the library for some reason.
Thanks a lot.
Excellent, glad you sorted it!
is working on a reply...