Copied to clipboard

Flag this post as spam?

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


  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 22, 2013 @ 20:18
    Fuji Kusaka
    0

    Display a NodeTypeAlias Once only from a list

    Can some explains how do i get the Name of NodeTypeAlias Once only from a list of Node from a folder which contains 10 different Document Type.

    The idea behind this is to be able to display the different NodeTypeAlias once in such a way that filtering of content can be done by using css.

    I tried something like this but doesnt work. Any suggestions please?

         string p = "";
         foreach(var i in Model.Children.OrderBy("NodeTypeAlias")){
            if(p != i.NodeTypeAlias){
               @i.NodeTypeAlias
            }  
         }

     

  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 22, 2013 @ 20:48
    Fuji Kusaka
    0

    So far the grouping is working but how do i get it to display the value once only instead the grouping?

     foreach(var i in n.Children.GroupBy("NodeTypeAlias")){
             
                 <li>
                     @foreach(var s in i){                     
                             @s.NodeTypeAlias
                     }
             </li>
         }
  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 22, 2013 @ 21:20
    Fuji Kusaka
    0

    well seems like

    if(s.IsFirst()){
     @s.NodeTypeAlias
    }

    is doing the trick

  • Dirk De Grave 4537 posts 6006 karma points MVP 3x admin c-trib
    Jul 22, 2013 @ 21:20
    Dirk De Grave
    0

    Fuji,

    Can't you use .Distinct() to get unique doc types?

     

    /Dirk

  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 22, 2013 @ 21:29
    Fuji Kusaka
    0

    Hi Dirk,

    Did saw a post from Tom about using .Distinct() values but didnt get to work though.

    There must be a better way instead of using Helpers here.

  • Dirk De Grave 4537 posts 6006 karma points MVP 3x admin c-trib
    Jul 22, 2013 @ 21:35
    Dirk De Grave
    0

    i'm sure i've used it before, just not sure what project... don't know about tom's example (no link)... i'll see if i can find the example (no promises tho)

    /Dirk

  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 22, 2013 @ 21:40
  • Dirk De Grave 4537 posts 6006 karma points MVP 3x admin c-trib
    Jul 22, 2013 @ 21:43
    Dirk De Grave
    2

    Ah ok, got it, my scenario was a tiny bit more complex. Anyway, should get it working using

    var aliases = Model.Children.Select(x => x.NodeTypeAlias).Distinct();

     

    /Dirk

  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 23, 2013 @ 08:52
    Fuji Kusaka
    0

    Hi Dirk,

    Got it working in a neater way !

        DynamicNode m = new DynamicNode(CurrentModel);
         foreach (var i in m.ChildrenAsList.Where(y=>y.GetProperty("umbracoNaviHide").Value !="1").Select(x=>x.NodeTypeAlias).Distinct()){
          <li><a href="#filter" data-option-value="">@i</a></li>   
    }
  • 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