Copied to clipboard

Flag this post as spam?

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


  • Craig O'Mahony 364 posts 918 karma points
    Oct 29, 2018 @ 11:50
    Craig O'Mahony
    0

    Pass multiple parameters to macro

    Hi,

    I've set up a macro a parameter (nodeID Integer) and from a partial view I'm calling the macro like this:

    @umbraco.RenderMacro("MembersMenu", new { nodeID = 6389 })
    

    This work fine but I've added another parameter (mobileClass textstring) and I've extended the call to:

    @umbraco.RenderMacro("MembersMenu", new { nodeID = 6390, mobileClass= "bg-palenavy" })
    

    I'm not getting any errors but the macro isn't reading in the 2nd parameter:

    var page = Umbraco.Content(Model.MacroParameters["nodeID"]);
    var mobileClass= Umbraco.Content(Model.MacroParameters["mobileClass"]);
    

    Any ideas anyone?

    C

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Oct 29, 2018 @ 12:24
    Michaël Vanbrabandt
    0

    Hi Craig,

    var mobileClass= Umbraco.Content(Model.MacroParameters["mobileClass"]);
    

    Now you are trying to find a content based on the mobileClass. Shouldn't this be:

    var mobileClass = (string)Model.MacroParameters["mobileClass"];
    

    Hope this helps!

    /Michaël

  • Craig O'Mahony 364 posts 918 karma points
    Oct 29, 2018 @ 14:22
    Craig O'Mahony
    0

    Hi Michael,

    Sadly that hasn't made any difference :(

    Thanks, C

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Oct 29, 2018 @ 14:30
    Michaël Vanbrabandt
    0

    Craig,

    did you add the parameter to your Macro in the backoffice:

    https://our.umbraco.com/documentation/reference/templating/macros/

    Hope this helps!

    /Michaël

  • Craig O'Mahony 364 posts 918 karma points
    Oct 29, 2018 @ 15:55
    Craig O'Mahony
    0

    I did indeedy

    enter image description here

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Oct 30, 2018 @ 07:41
    Michaël Vanbrabandt
    0

    Hi Craig,

    what is the result when you add the following into your Macro view:

    @Model.MacroParameters.Count
    

    /Michaël

  • Craig O'Mahony 364 posts 918 karma points
    Oct 30, 2018 @ 12:00
    Craig O'Mahony
    1

    This get's weirder!

    Adding @Model.MacroParameters.Count() results in 2 (which is what I'd expect)

    Adding

                foreach(var para in Model.MacroParameters)
                {
                    <p>@para.Key + @para.Value</p>
                }
    

    Results in nodeID + 10 mobileClass + bg-navy

    Which is what I'd expect

    But

    var mobileClass =Umbraco.Content(Model.MacroParameters["mobileClass"]);
    

    Returns null.

    Thanks, C

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Oct 30, 2018 @ 12:05
    Dave Woestenborghs
    0

    What does Model.MacroParameters["mobileClass"] return ?

    Dave

  • Craig O'Mahony 364 posts 918 karma points
    Oct 30, 2018 @ 12:06
    Craig O'Mahony
    0

    Nothing it's empty......

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Oct 30, 2018 @ 12:11
    Michaël Vanbrabandt
    0

    Craig,

    what if you change the key of mobileClass to something else like "responsive" ( also in your Umbraco backoffice in the macro parameters ).

    Does that help?

    /Michaël

  • Craig O'Mahony 364 posts 918 karma points
    Oct 30, 2018 @ 12:12
    Craig O'Mahony
    0

    Tried that it doesn't make any difference. Really odd

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Oct 30, 2018 @ 12:14
    Michaël Vanbrabandt
    0

    What if you only use the second parameter so if your remove the nodeID, do you then get the value for mobileClass?

    /Michaël

  • Craig O'Mahony 364 posts 918 karma points
    Oct 30, 2018 @ 12:15
    Craig O'Mahony
    0

    How'd you mean from the Macro parameters or in code?

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Oct 30, 2018 @ 12:17
    Michaël Vanbrabandt
    0

    both, so only have the mobileClass parameter to see if that works

    /Michaël

  • Craig O'Mahony 364 posts 918 karma points
    Oct 30, 2018 @ 12:20
    Craig O'Mahony
    0

    Nah, doesn't make any difference....

    I might have to hack this to load the value

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Oct 30, 2018 @ 12:21
    Dave Woestenborghs
    0

    What version of Umbraco are you using ?

    And can you reproduce it on a empty install ?

    Dave

  • Craig O'Mahony 364 posts 918 karma points
    Oct 30, 2018 @ 12:22
    Craig O'Mahony
    0

    7.6.4 I'll have to give that a go later

Please Sign in or register to post replies

Write your reply to:

Draft