Copied to clipboard

Flag this post as spam?

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


  • Alex Burr 77 posts 128 karma points
    Jan 20, 2014 @ 16:51
    Alex Burr
    0

    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:

    @inherits Umbraco.Web.Macros.PartialViewMacroPage

    @if (Model.MacroParameters["startNodeID"] != null)
    {
       
    @* Get the start node as a dynamic node *@
       
    var startNode = Umbraco.Content(Model.MacroParameters["startNodeID"]);

       
    if (startNode.Children.Where("Visible").Any())
       
    {
           
    <ul>
               
    @foreach (var page in startNode.Children.Where("Visible"))
               
    {
                   
    <li><a href="@page.Url">@page.Name</a></li>
               
    }
           
    </ul>
       
    }    
    }

    And GJSPage.cshtml template contains:

    ...
    <aside>
           
    @Umbraco.Field("sidebarMacro")
    </aside>
    ...

    The final page that is output has the following:

    ...
    <aside>
           
    <!--?UMBRACO_MACRO macroAlias="GJSSubNavigation" Start Node ID="1048" /-->
    </aside>
    ...

    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?

  • Alex Burr 77 posts 128 karma points
    Jan 21, 2014 @ 20:43
    Alex Burr
    0

    No one has experience in how to answer this?

    Does the macro container property just not work at all?

  • jivan thapa 194 posts 681 karma points
    Jan 21, 2014 @ 23:56
    jivan thapa
    0

    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"

  • Alex Burr 77 posts 128 karma points
    Jan 22, 2014 @ 04:08
    Alex Burr
    0

    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?

  • jivan thapa 194 posts 681 karma points
    Jan 22, 2014 @ 09:41
    jivan thapa
    0

    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"}

Please Sign in or register to post replies

Write your reply to:

Draft