Copied to clipboard

Flag this post as spam?

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


  • Keith Jackson 183 posts 552 karma points
    Jan 10, 2013 @ 00:18
    Keith Jackson
    0

    How do I pass parameters to and read from them in a Razor macro?

    I have an Umbraco 4.11 site with a Macro I have created. It has a parameter called ArticleId.

    I am currently trying to pass it like this...

    @Umbraco.RenderMacro("ForeignArticleWrapper", new { ArticleId = Umbraco.Field("featuredArticle").ToString() });

    I have also tried...

    @Umbraco.RenderMacro("ForeignArticleWrapper", new { ArticleId = 1090 });

     

    I am trying to render the value in the macro using

    @Parameter.ArticleId, but it returns nothing.

     

    What am I doing wrong?

  • Pancheri Damien 16 posts 35 karma points
    Feb 12, 2013 @ 15:36
    Pancheri Damien
    0

    I have the same problem but I can't find a single clue.

    It's like the @Umbraco.RenderMacro doesn't work! Even the syntax @Umbraco.RenderMacro("MacroName") doesn't work.

    Do you have found something?

     

    Thanks

  • CelticHarp 12 posts 52 karma points
    Feb 15, 2013 @ 15:54
    CelticHarp
    0

    I also have the same problem in Umbraco 6. Please help..

  • Keith Jackson 183 posts 552 karma points
    Feb 15, 2013 @ 16:45
    Keith Jackson
    0

    I ended up replacing all my Macros with Partial Views instead.

  • Charles Afford 1163 posts 1709 karma points
    Feb 16, 2013 @ 18:17
    Charles Afford
    0
  • CelticHarp 12 posts 52 karma points
    Feb 18, 2013 @ 09:03
    CelticHarp
    0

    Try 

    Model.MacroParameters["ArticleId"]

    instead of

    @Parameter.ArticleId ..

    This is tested for version 6, I don't know if it still works for v4.

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Feb 18, 2013 @ 13:00
  • Sarah 40 posts 104 karma points
    Feb 19, 2013 @ 16:07
    Sarah
    0

    Here are the first few lines of a macro I have that has a parameter being passed in. If you don't already have these inherits or usings, try adding them and see if you have any luck.

    @inherits umbraco.MacroEngines.DynamicNodeContext

    @using umbraco.MacroEngines;

    @using umbraco;

    @{

        var numItems = int.Parse(Parameter.numItems);

    }

  • Francis Benyah 35 posts 112 karma points
    Nov 20, 2015 @ 08:16
    Francis Benyah
    1

    You almost there. One major thing you missed was to add ArticleId in the list of parameters for the macro in the developer section

    In the template

    @Umbraco.RenderMacro("YourMacro" ,new {ArticleId = @Umbraco.Field("yourField")})
    

    In the XSLT

    <xsl:param name="ArticleId" select="/macro/ArticleId"/>
    

    Then you can do what you want with it

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

    Again don't forget to add ArticleId as a parameter to your macro from the developer section in umbraco

Please Sign in or register to post replies

Write your reply to:

Draft