Copied to clipboard

Flag this post as spam?

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


  • Steven Day 3 posts 23 karma points
    Oct 25, 2011 @ 11:08
    Steven Day
    0

    Multiple variables in select from Macro Parameters

    Hi All,

    I'm struggling with what is obviously a very simple task, I can't figure out why my xslt select won't work.

    Following the examples from these threads: http://our.umbraco.org/forum/developers/xslt/21244-Multiple-variables-in-select, http://our.umbraco.org/forum/developers/xslt/20270-Multiple-parameters-in-xlst-select I'm using the following code to output the value of a particular page property, and choosing which property dynamically though a parameter to my macro.

    I have the following XSLT:

    <xsl:param name="currentPage"/>
    <
    xsl:param name="heroImage" select="macro/heroImage"/>
    <
    xsl:template match="/"> 
    <
    div id="hero-credits">
       
    <xsl:variable name="mediaId" select="$currentPage/* [name() = concat('heroImage', $heroImage)]" />
       
    <xsl:variable name="media" select="umbraco.library:GetMedia($mediaId, 0)"/>
       
    <a href="{$media/creditLink}" title="{$media/credit}">
         
    <xsl:value-of select="$media/credit" />
       
    </a>
     
    </div>
    </
    xsl:template>


    Which is connected to a macro with a text parameter "heroImage" and is called from my template like this:

    <umbraco:Macro heroImage="[@image], 1" Alias="HeroCredits" runat="server"></umbraco:Macro>

    For now I'm just worrying about the default case, rather than getting the value from the Request. I've checked the parameters with xsl:copy-of statments and they're getting passed in correctly, and I've checked my xsl by making $mediaId hard-coded, and it all works fine, however, whenever I try the full thing I get the following error on saving my xslt:

    System.OverflowException: Value was either too large or too small for an Int32.


    It's definately coming from the statement that's assigning a value to $mediaId, but I can't for the life of me figure out why? What's the glaringly obvious mistake I've made?

    Thanks,

    Steve

  • Fuji Kusaka 2203 posts 4220 karma points
    Oct 25, 2011 @ 11:14
    Fuji Kusaka
    1

    Hi Steeve

    Can you try this 

    <xsl:if test ="$heroImage">
    <xsl:variable name="mediaId" select="$currentPage/* [name() = concat('heroImage', $heroImage)]" />
        <xsl:variable name="media" select="umbraco.library:GetMedia($mediaId, 0)"/>
        <a href="{$media/creditLink}" title="{$media/credit}">      <xsl:value-of select="$media/credit" />
        </a> 
    </xsl:if>
  • Steven Day 3 posts 23 karma points
    Oct 25, 2011 @ 11:35
    Steven Day
    0

    Hey, that works! Thanks very much. Can you explain why it works? Do I need to do this every time I use a parameter in this way?

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Oct 25, 2011 @ 11:45
    Chriztian Steinmeier
    1

    Hi Steven,

    The error occurs because the GetMedia() function is called with an empty string instead of an ID.

    Check my answer here for a "safe" way to handle media.

    /Chriztian

     

  • Steven Day 3 posts 23 karma points
    Oct 25, 2011 @ 11:57
    Steven Day
    0

    Thanks Chriztian, it makes more sense now!

  • Fuji Kusaka 2203 posts 4220 karma points
    Oct 25, 2011 @ 12:12
    Fuji Kusaka
    0

    Nice one Chriztian....

Please Sign in or register to post replies

Write your reply to:

Draft