I tried posting this in the Using Umbraco 7 forum and didn't get any responses. So maybe this is a better place to ask: How do I correctly use a macro with a content picker parameter inside a macro container document property?
I'm running v7.0.1 and setting up a new website. I have a macro called GJSSubNavigation that renders ~/Views/MacroPartials/GJSSubNavigation.cshtml. It has one parameter, startNodeID, that is a content picker.
There is a document type called GJSPage that uses a template GJSPage.cshtml. The document type has a property called sidebarMacro that is a macro container.
However when I attempt to assign the GJSSubNavigation macro to the sidebarMacro property on the page, and choose the appropriate node, the content does not render correctly. Instead the macro alias and start node are output in an HTML comment.
The file GJSSubNavigation.cshtml contains:
@inheritsUmbraco.Web.Macros.PartialViewMacroPage
@if(Model.MacroParameters["startNodeID"]!=null) { @*Get the start node as a dynamic node *@ var startNode =Umbraco.Content(Model.MacroParameters["startNodeID"]);
Not really viable, since I won't know the start node in the template, I want the user to choose it dynamically. That's why there's a start node parameter in my macro, that is a Content Picker.
The problem is that this is only one of many possible macros I may want to render at that point in the template. That's why the Macro Container type exists for properties in the Document Type.
I've gotten this to work before on v4x with XSLT macros but I'm doing a new project in v7 with Razor. My question is, does the Macro Container type not work correctly, or is it not compatible with macro partials? Should I fall back to a user control?
Start node does not need to be static. It can be dynamic. Use @CurrentPage.YourDocumentTypePropertyAlias to get the value. And pass the value to macro parameter.
@Umbraco.RenderMacro("GJSSubNavigation", new { startNodeID = "@CurrentPage.sidebarMacro"}
Using Content Picker in Macro Container property
Hi,
I tried posting this in the Using Umbraco 7 forum and didn't get any responses. So maybe this is a better place to ask: How do I correctly use a macro with a content picker parameter inside a macro container document property?
I'm running v7.0.1 and setting up a new website. I have a macro called GJSSubNavigation that renders ~/Views/MacroPartials/GJSSubNavigation.cshtml. It has one parameter, startNodeID, that is a content picker.
There is a document type called GJSPage that uses a template GJSPage.cshtml. The document type has a property called sidebarMacro that is a macro container.
However when I attempt to assign the GJSSubNavigation macro to the sidebarMacro property on the page, and choose the appropriate node, the content does not render correctly. Instead the macro alias and start node are output in an HTML comment.
The file GJSSubNavigation.cshtml contains:
And GJSPage.cshtml template contains:
The final page that is output has the following:
The macro alias and ID of the start node appear to be correct, however the macro content is not being rendered.
Does anyone have experience with this?
No one has experience in how to answer this?
Does the macro container property just not work at all?
I did not understand what do you mean "macro container property".
Anyway. Have you tried using marco directly on the template "GJSPage.cshtml". ?
Something like this on the template "GJSPage.cshtml"
Not really viable, since I won't know the start node in the template, I want the user to choose it dynamically. That's why there's a start node parameter in my macro, that is a Content Picker.
The problem is that this is only one of many possible macros I may want to render at that point in the template. That's why the Macro Container type exists for properties in the Document Type.
I've gotten this to work before on v4x with XSLT macros but I'm doing a new project in v7 with Razor. My question is, does the Macro Container type not work correctly, or is it not compatible with macro partials? Should I fall back to a user control?
Start node does not need to be static. It can be dynamic. Use @CurrentPage.YourDocumentTypePropertyAlias to get the value. And pass the value to macro parameter.
@Umbraco.RenderMacro("GJSSubNavigation", new { startNodeID = "@CurrentPage.sidebarMacro"}
is working on a reply...