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!
Is it possible to use a nested content property as a macro parameter? Like so:
var items = CurrentPage.GetPropertyValue<IEnumerable<IPublishedContent>>("items"); @Umbraco.RenderMacro("SomeMacro", new { items = items });
My question is how do I parse the <IEnumerable<IPublishedContent>> to the macro as a parameter?
<IEnumerable<IPublishedContent>>
This is what I have so far in the macro view (not working):
var items = Model.MacroParameters["items"] as IEnumerable<IPublishedContent>; foreach(var item in items) { ... }
Thanks!!!
Hi Mathias
You have to cast macro param like that:
var items = Model.MacroParameters["items"] as IEnumerable<IPublishedContent>;
Thanks,
Alex
Hi Alex! Im getting System.NullReferenceException: Object reference not set to an instance of an object. on the foreach line. Does it matter which parameter type items is set to?
System.NullReferenceException: Object reference not set to an instance of an object.
I have an idea, why did you pass CurrentPage field to macro?
You can use in the macro:
var items = CurrentPage.GetPropertyValue<IEnumerable<IPublishedContent>>("items");
Yeah that would work, but I didn't mention that the nested content is a property on another nested content, so CurrentPage is not an option :(
var items = OtherNestedContentItem.GetPropertyValue<IEnumerable<IPublishedContent>>("items"); @Umbraco.RenderMacro("SomeMacro", new { items = items});
My question is how do I parse the <IEnumerable<IPublishedContent>> to the macro as a parameter or if you have another solution to this problem?
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Nested content as a macro parameter
Hi!
Is it possible to use a nested content property as a macro parameter? Like so:
My question is how do I parse the
<IEnumerable<IPublishedContent>>
to the macro as a parameter?This is what I have so far in the macro view (not working):
Thanks!!!
Hi Mathias
You have to cast macro param like that:
Thanks,
Alex
Hi Alex! Im getting
System.NullReferenceException: Object reference not set to an instance of an object.
on the foreach line. Does it matter which parameter type items is set to?Hi Mathias
I have an idea, why did you pass CurrentPage field to macro?
You can use in the macro:
Thanks,
Alex
Yeah that would work, but I didn't mention that the nested content is a property on another nested content, so CurrentPage is not an option :(
My question is how do I parse the
<IEnumerable<IPublishedContent>>
to the macro as a parameter or if you have another solution to this problem?is working on a reply...