Copied to clipboard

Flag this post as spam?

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


  • Allie 26 posts 116 karma points
    Aug 03, 2021 @ 14:53
    Allie
    0

    Hi everyone , can sb help me w/ it ?..

    now

    how it should be

                                    @{
                                var groups = item.Children.GroupBy(i => i.Value("category"));
                                }
    
    
                                    @foreach(var category in groups)
                                    {  
                                       <div class="submenu-row">
                                            <div class="submenu-column">
                                                <p>@category.Key</p>
    
                                            @foreach(var subitem in category)
                                            {
                                                <a href="@subitem.Value("contentLink")" title="@subitem.Value("title")">@subitem.Name</a>
                                            }
    
                                            </div>
                                              </div>
                                    }
    

    Any ideas how to render it correctly ? I was trying to render

    in the condition , but umraco did not let me to do it. Basically , the main goal is to render every 2 categories in pairs wrapping in a div which stands for rows , but now it's devided on rows for each category ( or i can wrap it in just one big row).

    Kind regards :) ty in advance <3

  • Søren Gregersen 441 posts 1884 karma points MVP 2x c-trib
    Aug 03, 2021 @ 15:43
    Søren Gregersen
    0

    I think this could get you a bit closer:

    @foreach(var category in groups)
    {  
        <p>@category.Key</p>
        @foreach(var row in category.InGroupsOf(2))
        {
            <div class="submenu-row">
            @foreach(var subitem in row)
            {
                <div class="submenu-column">
                    <a href="@subitem.Value("contentLink")" title="@subitem.Value("title")">@subitem.Name</a>
                </div>
            }
            </div>
        }            
    }
    
  • Allie 26 posts 116 karma points
    Aug 03, 2021 @ 16:01
    Allie
    0

    It's displaying like this :

    asd

    I tried to change your code back and forth , but idk .. thx anyways.

  • Søren Gregersen 441 posts 1884 karma points MVP 2x c-trib
    Aug 03, 2021 @ 16:14
    Søren Gregersen
    0

    how about this, then :

    @foreach(var row in groups.InGroupsOf(2))
    {  
        <div class="submenu-row">
        @foreach(var item in row)
        {
            <div class="submenu-column">
            <p>@category.Key</p>
            @foreach(var subitem in row)
            {
                <a href="@subitem.Value("contentLink")" title="@subitem.Value("title")">@subitem.Name</a>
            }
            </div>
        }            
        </div>
    }
    
  • Allie 26 posts 116 karma points
    Aug 03, 2021 @ 16:25
    Allie
    0

    you probably forgot to put category smw , look :

    qwe

  • Søren Gregersen 441 posts 1884 karma points MVP 2x c-trib
    Aug 03, 2021 @ 16:27
    Søren Gregersen
    0

    can't check the code, when I don't have your solution setup ;)

    @foreach(var row in groups.InGroupsOf(2))
    {  
        <div class="submenu-row">
        @foreach(var item in row)
        {
            <div class="submenu-column">
            <p>@item.Key</p>
            @foreach(var subitem in item)
            {
                <a href="@subitem.Value("contentLink")" title="@subitem.Value("title")">@subitem.Name</a>
            }
            </div>
        }            
        </div>
    }
    

    Something like that?

  • Allie 26 posts 116 karma points
    Aug 03, 2021 @ 16:38
    Allie
    0

    so far so good

    how about to wrap "view all" item ( item without category ) in a separate row , so it should be wrapped in a

    ..
    and then all the categories go in pairs

    1 2 3

  • Søren Gregersen 441 posts 1884 karma points MVP 2x c-trib
    Aug 03, 2021 @ 16:48
    Søren Gregersen
    0

    something like...

    @{
        var categories = item.Children
            .GroupBy(i => i.Value<string>("category"))
            .Select(x => new {
                Category = x.Key,
                Links = x.Select(y => new {
                    Link = y.Value<string>("contentLink"),
                    Title = y.Value<string>("title"),
                    Name = y.Name,
                }).ToArray(),
            }).ToList();
    
        categories.Insert(0,
            new{
                Category = string.Empty,
                Links = new[]{
                    new {
                        Link = "some/where",
                        Title = string.Empty,
                        Name = "View All"
                    }
                }
            });
    
    
        foreach(var row in categories.InGroupsOf(2))
        {  
            <div class="submenu-row">
            @foreach(var item in row)
            {
                <div class="submenu-column">
                @if(!string.IsNullOrWhiteSpace(item.Category)){
                    <p>@item.Category</p>
                }
                @foreach(var link in item.Links)
                {
                    <a href="@link.Link" title="@link.Title">@link.Name</a>
                }
                </div>
            }            
            </div>
        }
    }
    
  • Allie 26 posts 116 karma points
    Aug 03, 2021 @ 16:57
    Allie
    0

    okay , smth wrong with key , take a look :

    1

    but i just deleted this line ahhahah to see how it will be without category names

    2

    dope af , if we can fix repeating item "view all" and rendering categories

  • Søren Gregersen 441 posts 1884 karma points MVP 2x c-trib
    Aug 03, 2021 @ 17:06
    Søren Gregersen
    0

    well, I think you should be able to get it working with the bits I've given.

    I can't see why you get the "View all" two times -- it's only in the list once.

  • Allie 26 posts 116 karma points
    Aug 03, 2021 @ 17:14
    Allie
    0

    it's because i actually have a page in my content named "view all"

    rty

    but even when i deleted it

    asd

    cuz the row div isn't close afted view all rendered

    qwe

    final result , if let's go ultra last one w/ rendering it in a separe row

    zxc

  • Allie 26 posts 116 karma points
    Aug 03, 2021 @ 17:22
    Allie
    0

    we need pretty much just to start rendering in pairs if it's not "view all" item , simply saying to make render it just a bit differently. hope u understand me ;)

  • Søren Gregersen 441 posts 1884 karma points MVP 2x c-trib
    Aug 03, 2021 @ 22:09
    Søren Gregersen
    100

    you will need to identify the "view all" link somehow. There is no way to ensure that the "view all" is the only link without a category, so checking for an empty category may not be enough.

    Other than that :

    @{
        var categories = item.Children
            .GroupBy(i => i.Value<string>("category"))
            .Select(x => new {
                Category = x.Key,
                Links = x.Select(y => new {
                    Link = y.Value<string>("contentLink"),
                    Title = y.Value<string>("title"),
                    Name = y.Name,
                }).ToArray(),
            }).ToList();
    
        foreach(var row in categories.Where(x => string.IsNullOrWhiteSpace(x.Category)))
        {  
            <div class="submenu-row">
            @foreach(var item in row)
            {
                <div class="submenu-column should-be-full-width">
                @foreach(var link in item.Links)
                {
                    <a href="@link.Link" title="@link.Title">@link.Name</a>
                }
                </div>
            }            
            </div>
        }
    
        foreach(var row in categories.Where(x => !string.IsNullOrWhiteSpace(x.Category)).InGroupsOf(2))
        {  
            <div class="submenu-row">
            @foreach(var item in row)
            {
                <div class="submenu-column">
                    <p>@item.Category</p>
                    @foreach(var link in item.Links)
                    {   
                        <a href="@link.Link" title="@link.Title">@link.Name</a>
                    }
                </div>
            }            
            </div>
        }
    }
    
  • Allie 26 posts 116 karma points
    Aug 04, 2021 @ 09:05
    Allie
    0

    Couldn't have done it without you, understood the idea, goddamn code don't wanna work though.

    desc

  • Søren Gregersen 441 posts 1884 karma points MVP 2x c-trib
    Aug 04, 2021 @ 09:22
    Søren Gregersen
    0

    is you casing correct? Item <> item

  • Allie 26 posts 116 karma points
    Aug 04, 2021 @ 09:26
    Allie
    0

    ohh, i know it, i just changed item to Item, cuz i already using name item in my code

    anyways, it's throwing an error

Please Sign in or register to post replies

Write your reply to:

Draft