Copied to clipboard

Flag this post as spam?

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


  • Emil Tinebo 19 posts 39 karma points
    Aug 30, 2011 @ 16:15
    Emil Tinebo
    0

    Passing variable to GetMedia causes error

    Hey,

    I have some strange issues with umbrac.library.GetMedia. Consider the  example blow.
    I have a property called storeIcon which has data type Media Picker. When I store this property in a variable and output the variable the value 1254 is printed. When I pass this variable into the GetMedia method the xslt crash with error System.OverflowException: Value was either too large or too small for an Int32. When I hard code its value (as the example shows below) the image is rendered. What am I doing wrong here?

    <xsl:for-each select="current()/* [name() = $recordStoreTypeAlias]">
                <xsl:variable name="storeIcon" select="number(storeIcon)" />
    <xsl:value-of select="$storeIcon"/>
    <xsl:variable name="thumbnail" select="umbraco.library:GetMedia($storeIcon, 0)" /> <--This row generates the error
                <xsl:variable name="thumbnail" select="umbraco.library:GetMedia('1254', 0)" /> <-- This row works
                <img src="{$thumbnail/umbracoFile}" />
              </xsl:for-each>
  • Rich Green 2246 posts 4006 karma points
    Aug 30, 2011 @ 16:21
    Rich Green
    0

    Hey,

    If you add a check like this your problem will go away.

     

    <xsl:for-each select="current()/* [name() = $recordStoreTypeAlias]">

                <xsl:variable name="storeIcon" select="number(storeIcon)" />

                <xsl:value-of select="$storeIcon"/>

     

    <xsl:if test="$storeIcon != '' ">

                <xsl:variable name="thumbnail" select="umbraco.library:GetMedia($storeIcon, 0)" />   <--This row generates the error

    </xsl:if>

                <xsl:variable name="thumbnail" select="umbraco.library:GetMedia('1254', 0)" />   <-- This row works

                <img src="{$thumbnail/umbracoFile}" />

              </xsl:for-each>

     

    Rich

  • Emil Tinebo 19 posts 39 karma points
    Aug 30, 2011 @ 16:37
    Emil Tinebo
    0

    It didn't work. Still the same error.

  • Rich Green 2246 posts 4006 karma points
    Aug 30, 2011 @ 16:53
    Rich Green
    0

    Sorry!

    Should be

    <xsl:if test="$storeIcon &gt; 0>
                <xsl:variable name="thumbnail" select="umbraco.library:GetMedia($storeIcon, 0)" /> 
    </xsl:if>

    Rich :)

  • Emil Tinebo 19 posts 39 karma points
    Aug 30, 2011 @ 16:54
    Emil Tinebo
    0

    Got it working now!

    Instead of using a variable I check the storeIcon property directly in the if-statement and then use it in the GetMedia method if it is not empty.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies