Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
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
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
Hi Michael,
Sadly that hasn't made any difference :(
Thanks, C
Craig,
did you add the parameter to your Macro in the backoffice:
https://our.umbraco.com/documentation/reference/templating/macros/
I did indeedy
what is the result when you add the following into your Macro view:
@Model.MacroParameters.Count
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.
What does Model.MacroParameters["mobileClass"] return ?
Dave
Nothing it's empty......
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?
Tried that it doesn't make any difference. Really odd
What if you only use the second parameter so if your remove the nodeID, do you then get the value for mobileClass?
How'd you mean from the Macro parameters or in code?
both, so only have the mobileClass parameter to see if that works
Nah, doesn't make any difference....
I might have to hack this to load the value
What version of Umbraco are you using ?
And can you reproduce it on a empty install ?
7.6.4 I'll have to give that a go later
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
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:
This work fine but I've added another parameter (mobileClass textstring) and I've extended the call to:
I'm not getting any errors but the macro isn't reading in the 2nd parameter:
Any ideas anyone?
C
Hi Craig,
Now you are trying to find a content based on the mobileClass. Shouldn't this be:
Hope this helps!
/Michaël
Hi Michael,
Sadly that hasn't made any difference :(
Thanks, C
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
I did indeedy
Hi Craig,
what is the result when you add the following into your Macro view:
/Michaël
This get's weirder!
Adding @Model.MacroParameters.Count() results in 2 (which is what I'd expect)
Adding
Results in nodeID + 10 mobileClass + bg-navy
Which is what I'd expect
But
Returns null.
Thanks, C
What does Model.MacroParameters["mobileClass"] return ?
Dave
Nothing it's empty......
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
Tried that it doesn't make any difference. Really odd
What if you only use the second parameter so if your remove the nodeID, do you then get the value for mobileClass?
/Michaël
How'd you mean from the Macro parameters or in code?
both, so only have the mobileClass parameter to see if that works
/Michaël
Nah, doesn't make any difference....
I might have to hack this to load the value
What version of Umbraco are you using ?
And can you reproduce it on a empty install ?
Dave
7.6.4 I'll have to give that a go later
is working on a reply...