Copied to clipboard

Flag this post as spam?

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


  • Tom Maton 387 posts 660 karma points
    Apr 07, 2014 @ 23:04
    Tom Maton
    0

    Getting children results and splitting into rows of 3

    Hi All,

    Its been about 3 years since I've worked on a full blown Umbraco project and I'm a bit rusty with my razor syntax.

    I've taken the standard List nodes from changeable resource.

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

    Of which it will always return 6 items but I want to split these onto two rows of 3 like so

    <ul>
    <li>Item 1</li>
    <li>Item 2</li>
    <li>Item 3</li>
    </ul>
    <ul>
    <li>Item 4</li>
    <li>Item 5</li>
    <li>Item 6</li>
    </ul>

    But cant for the live of me remeber how to do it.:(

    Thanks in advance.

    Tom

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Apr 07, 2014 @ 23:43
    Dennis Aaen
    1

    Hi Tom.

    Take a look at this simple inGroupOf, example I think that it can help you.

    https://gist.github.com/nul800sebastiaan/1067257

    And you can find the documentation here

    @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").InGroupsOf(3)){
                   
    foreach(var page ingroup)                
                       
    <li>
                           
    <a href="@page.Url">
                               
    @page.Name
                           
    </a>
                        </
    li>
                         
    }
           
    </ul>
       
    }    
    }

    hope this help you,

    /Dennis

  • user111 4 posts 74 karma points
    Dec 09, 2016 @ 03:24
    user111
    0

    Hi Dennis! I want show content paragraph

    <ul class="left">
       <li>Item 1</li>
        <li>Item 3</li>
        <li>Item 5</li>
    </ul>
    <ul class="right">
       <li>Item 2</li>
        <li>Item 4</li>
        <li>Item 6</li>
    </ul>
    

    But i can't. You can help me!

Please Sign in or register to post replies

Write your reply to:

Draft