Copied to clipboard

Flag this post as spam?

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


  • FarmFreshCode 225 posts 422 karma points
    Sep 17, 2012 @ 15:58
    FarmFreshCode
    0

    Retrieve Media Picker URL from file in XSLT

    Ok so here is my issue. Currently using Umbraco 4.8.1 and trying to place the link to the attached Media file for a node in my navigation. This navigation menu dynamically calls all child nodes, however IF the child node with a DocType of "Media Redirect" I need to have the file path of the attached file used as the link and not the node ID.

    Here are some of my basic values to use in the solution

    DocType Alias = MediaRedirect

    using a dataType = Media Picker
    Alias = mediaLink

    So I have tried using a script like this:

       <xsl:when test="mediaLink != ''">
    <a href="{mediaLink}" target="_blank" style="padding-left:30px;">
    <!-- output an extra class if there are children below this node -->
    <xsl:if test="$currentNode/*[@isDoc]"><xsl:attribute name="class">quadexpandable</xsl:attribute></xsl:if>
    <xsl:value-of select="@nodeName" />
    </a>
    </xsl:when>

    But that just gives me the Node ID.. and not the file path to the attached file... which is what I really want.. I've tried a lot of other solutions like this one:

        <xsl:when test="mediaLink != ''">
    <a href="{umbraco.library:GetMedia($currentPage/mediaLink,false)/umbracoFile}" target="_blank" style="padding-left:30px;">
    <!-- output an extra class if there are children below this node -->
    <xsl:if test="$currentNode/*[@isDoc]"><xsl:attribute name="class">quadexpandable</xsl:attribute></xsl:if>
    <xsl:value-of select="@nodeName" />
    </a>
    </xsl:when>

    But have not been able to correctly create a herf URL link that is correct or that doesn't break the script. Can someone please help!  Thank you in advance!

     

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Sep 17, 2012 @ 17:15
    Tom Fulton
    1

    Hi,

    The second way is what you want, except it looks like you're pulling mediaLink from the currentPage instead of the current node in your loop.  You should also check if its empty, otherwise you can get an error.  Try something like this:

     

    <xsl:when test="mediaLink != '' and mediaLink &gt; 0">
    <xsl:variable name="media" select="umbraco.library:GetMedia(mediaLink, false())" />
    <xsl:if test="not($media/error)"> <!-- make sure the media still exists -->
    <a href="{$media/umbracoFile}" target="_blank"  style="padding-left:30px;">
    <!-- output an extra class if there are children below this node -->
    <xsl:if test="$currentNode/*[@isDoc]"><xsl:attribute name="class">quadexpandable</xsl:attribute></xsl:if>  
    <xsl:value-of select="@nodeName" />
    </a>
    </xsl:if>
    </xsl:when>

     

    -Tom

  • FarmFreshCode 225 posts 422 karma points
    Sep 17, 2012 @ 20:46
    FarmFreshCode
    0

    THANKS TOM!

Please Sign in or register to post replies

Write your reply to:

Draft