Copied to clipboard

Flag this post as spam?

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


  • Haris 12 posts 32 karma points
    Jun 02, 2011 @ 15:18
    Haris
    0

    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

  • Jason Prothero 414 posts 1222 karma points c-trib
    Jun 02, 2011 @ 18:32
    Jason Prothero
    0

    Try this:

     

    <xsl:variable name="media" select="umbraco.library:GetMedia($sliderImage, false)" />

  • James Patterson 53 posts 192 karma points
    Jun 02, 2011 @ 18:39
    James Patterson
    0

     

    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

     

  • Nik Wahlberg 639 posts 1235 karma points MVP
    Jun 02, 2011 @ 18:59
    Nik Wahlberg
    0

    What do you get if you do a:

    <xsl:copy-of select="$media"/>

    -- Nik

  • Haris 12 posts 32 karma points
    Jun 02, 2011 @ 22:01
    Haris
    0

    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.

  • James Patterson 53 posts 192 karma points
    Jun 02, 2011 @ 22:52
    James Patterson
    0

    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?

  • Jason Prothero 414 posts 1222 karma points c-trib
    Jun 02, 2011 @ 22:55
    Jason Prothero
    0

    Any chance a content republish would help?

  • Haris 12 posts 32 karma points
    Jun 03, 2011 @ 00:01
    Haris
    0

    Hi,

    the problem is solved. James was right. I had to upload the images again to the library for some reason.

    Thanks a lot.

     

  • James Patterson 53 posts 192 karma points
    Jun 03, 2011 @ 00:08
    James Patterson
    0

    Excellent, glad you sorted it!

Please Sign in or register to post replies

Write your reply to:

Draft