Copied to clipboard

Flag this post as spam?

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


  • mfeola 117 posts 221 karma points
    Apr 21, 2011 @ 18:08
    mfeola
    0

    Can I pass a MultiNode as Parameter to Macro

    I have a few multinode pickers on my site and I would like to display the contents of all of them on one page.  I would rather not make 5 different XSLT files and Macros to make this work so I was trying to pass in the information as a parameter. 

     

    <umbraco:Macro SelectedNodes="[$selectedNodes]" Alias="SetCatCarousel" runat="server"></umbraco:Macro>

    And in the macro it starts off like so

    <xsl:variable name="MultiNodeItem" select="/macro/MultiNode"/>
    
    <xsl:template match="/">
        <xsl:call-template name="CarouselMultiNode">
          <xsl:with-param name="MultiNode" select="$MultiNodeItem"></xsl:with-param>
        </xsl:call-template>
    </xsl:template>
    <xsl:template name="CarouselMultiNode">
      <xsl:param name="MultiNode" />
    
      <xsl:if test="$MultiNode/MultiNodePicker/nodeId">
    
    <-- More Code, you don't need to see it -->
    
      </xsl:if>
    
    </xsl:template>
    

    I know that the template works because if I pass in my parameter with the $currentPage/multinode arguement it works fine.  Does anyone have a suggestion on how to get this to work? 

     

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Apr 21, 2011 @ 18:24
    Tom Fulton
    1

    Hi,

    If I recall, you can't pass in XML content through the Macro Parameter Syntax ( [#fieldName] ).

    So, one way around this would be to adjust your MultiNodePickers to store as CSV rather than XML.

    However, another idea which I think is better, is to instead pass in the Property Alias of the MNTP property to your macro, and retrieve the XML values from there.  Something like this, assuming your MNTP property alias is 'pageCarouselItems':

    <umbraco:Macro SelectedNodesProperty="pageCarouselItems" Alias="SetCatCarousel" runat="server"></umbraco:Macro>

    Then in your macro:

    <xsl:param name="selectedNodesProperty" select="/macro/SelectedNodesProperty" />
    <xsl:variable name="MultiNodeItem" select="$currentPage/* [not(@isDoc)][name() = $selectedNodesProperty]" />

    On an unrelated note, if you haven't seen it alreayd check out Chriztian's blog post on Using the Multi-Node Tree Picker in XSLT - he has a very cool "helper" function that makes it super easy to iterate through MNTP items without needing to use umbraco.library:GetXmlNodeById.  Looks like you're already on the right track using templates though.

    Hope this helps,
    Tom

     

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Apr 21, 2011 @ 18:26
    Tom Fulton
    1

    Oops - I just noticed that you were using the dollar sign to get the value recursively.  In this case in your XSLT you could use something like:

    <xsl:variable name="MultiNodeItem" select="$currentPage/ancestor-or-self::* [not(@isDoc)][name() = $selectedNodesProperty]" />
  • mfeola 117 posts 221 karma points
    Apr 21, 2011 @ 19:33
    mfeola
    0

    that works great! thank you! 

Please Sign in or register to post replies

Write your reply to:

Draft