Copied to clipboard

Flag this post as spam?

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


  • Robert Dougan 48 posts 154 karma points
    Oct 15, 2009 @ 16:45
    Robert Dougan
    0

    umbraco.Library:GetMedia() Problem

    Can someone tell me why this doesn't work:

    <xsl:variable name="mediaLinkId" select="data [@alias = 'media']"/>

    <xsl:variable name="mediaUrl" select="umbraco.library:GetMedia($mediaLinkId, 1)/data" />

    The mediaLinkId variable is set correctly but the problem comes when I try and use the variable with the GetMedia call, it throws a parsing error. Should this not work?

    Any help would be appreciated!

    Cheers,

    Robert

  • dandrayne 1138 posts 2262 karma points
    Oct 15, 2009 @ 16:51
    dandrayne
    1

    Try wrapping a check around it

    <xsl:if test="string($mediaLinkId) != ''">
    <xsl:variable name="mediaUrl" select="umbraco.library:GetMedia($mediaLinkId, 1)/data" />
    </xsl:if>

    Dan

  • Robert Dougan 48 posts 154 karma points
    Oct 15, 2009 @ 16:59
    Robert Dougan
    0

    Yep, that seems to have worked, great thanks!

    What's the explanation for the solution?

    Robert

  • Robert Dougan 48 posts 154 karma points
    Oct 15, 2009 @ 17:01
    Robert Dougan
    0

    Ah, I'm an idiot, that's the explanation! This code was in a loop and some of the elements will not have a media link id set, hence it was breaking! D'oh!

    Cheers for your quick reply!

  • Sean Holmesby 61 posts 82 karma points
    May 24, 2011 @ 01:27
    Sean Holmesby
    0

    Haha....I had this exact same problem.... and couldn't figure it out.

    Shows you should always check a value of a field in code before you use it.

     

    This drove me nuts!

Please Sign in or register to post replies

Write your reply to:

Draft