Copied to clipboard

Flag this post as spam?

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


  • Lee 95 posts 115 karma points
    Jul 26, 2013 @ 12:11
    Lee
    0

    Media library issues

    Hi, I have a node referenced in my flow which I am capturing via a contentpicker called 'contentSource' I have a property in that called 'contentSource'.

    I am then trying to display that image on my page. However, when I save the following code, I get the error message displayed at the bottom.

    Hope you can help, many thanks.

     

     

    <xsl:param name="currentPage"/>

    <xsl:variable name="source" select="$currentPage/contentSource"/>

    <xsl:variable name="media" select="umbraco.library:GetMedia(umbraco.library:GetXmlNodeById($source)/topImage, 0)" />

    <!-- The fun starts here -->

    <xsl:if test="$media">

    <img class="topImage" src="{$media/umbracoFile}" alt="{$media/umbracoTag}" width="{$media/umbracoWidth}" height="{$media/umbracoHeight}"/>

    </xsl:if>

     

     

     

  • Lee 95 posts 115 karma points
    Jul 26, 2013 @ 12:13
    Lee
    0

    By the way, if I skip testing the image actually displays!?

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Jul 26, 2013 @ 13:28
    Chriztian Steinmeier
    1

    Hi Lee,

    Yes - the reason you're getting that error is because Umbraco will do some checking on the XSLT to see if it's at least a "valid" file before saving it, so it will execute a transform where it will use "Content" as $currentPage. That node doesn't have a contentSource property and since the XSLT assumes that one is there *and* that it has a valid media ID, the call to GetMedia() fails. You can safeguard against this with a simple if instruction:

    <xsl:template match="/">
        <xsl:if test="normalize-space($currentPage/contentSource)">
            ...
        </xsl:if>    
    </xsl:template>
    

    /Chriztian

  • Lee 95 posts 115 karma points
    Jul 26, 2013 @ 15:19
    Lee
    0

    Perfect... works a treat. Thanks Chriztian!

Please Sign in or register to post replies

Write your reply to:

Draft