Copied to clipboard

Flag this post as spam?

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


  • Dibs 202 posts 991 karma points
    Jun 25, 2015 @ 17:56
    Dibs
    0

    Access Marco parameters and add to a list

    Dear Umbraco Forum Team

    Would like to create list from a marco parameter within a macro used multiple times in a grid layout.

    Could you advise best practice to achieve this?

    Thanks Dibs

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jun 25, 2015 @ 18:27
    Dennis Aaen
    0

    Hi Dibs,

    You could use this code below, with this you will get the child nodes from the current page, of a changeable source.

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    
    
    @*
    
        Macro to list all child pages under a specific page in the content tree.
    
    
        How it works:
    
            - Confirm the startNodeId macro parameter has been passed in with a value
    
            - Loop through all child pages
    
            - Display a list of link to those pages, sorted by the value of the propertyAlias
    
        Macro Parameters To Create, for this macro to work:
    
        Alias:startNodeId     Name:Select starting page    Type:Content Picker
    
    *@
    
    
    @{ var startNodeId = Model.MacroParameters["startNodeId"]; }
    
    @if (startNodeId != null)
    
    {
    
        @* Get the starting page *@
    
        var startNode = Umbraco.Content(startNodeId);
    
        var selection = startNode.Children.Where("Visible");
    
    
    
        if (selection.Any())
    
        {
    
            <ul>
    
                @foreach (var item in selection)
    
                {
    
                    <li>
    
                        <a href="@item.Url">@item.Name</a>
    
                    </li>
    
                }
    
            </ul>
    
        }
    
    }
    

    If I have misunderstood what you are trying to do, then if you can explain it more detailed then I am sure that we can help you.

    Hope this helps,

    /Dennis

  • Dibs 202 posts 991 karma points
    Jun 25, 2015 @ 18:57
    Dibs
    0

    Cheers Dennis

    I can create the above via the partial views no problem.

    What I have is a macro with title a field, this macro is added multiple times to a grid layout. I would like to extract all title fields from the macros within the grid and add them to a list.

    Hope that makes sense

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jun 25, 2015 @ 19:01
    Dennis Aaen
    0

    Hi Dibs,

    That make sense now, I am not sure how you can archive this, or if this is possible, perhaps other in the great community, knows if this is possible.

    /Dennis

  • René Pjengaard 118 posts 702 karma points c-trib
    Jun 25, 2015 @ 19:38
    René Pjengaard
    101

    Hi Dibs,

    maybe you should try downloading the Skybrud.Umbraco.GridData NuGet. This gives your grid a model, and then you can iterate through your rows and find the macros you want. I don´t know if it will work, but i think it would be possible.

    NuGet: https://www.nuget.org/packages/Skybrud.Umbraco.GridData/

    Github: https://github.com/skybrud/Skybrud.Umbraco.GridData

    But then again. Using Grid to generate a list, is not the finest way. But i´m sure you have your reasons.

    /René

  • Dibs 202 posts 991 karma points
    Jun 25, 2015 @ 22:02
    Dibs
    0

    Cheers René

    I'll have a look at your suggestion. I do have my reasons, they are clients : (

    Thanks Dibs

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies