Copied to clipboard

Flag this post as spam?

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


  • BrianAhle 4 posts 34 karma points
    Feb 20, 2013 @ 20:31
    BrianAhle
    0

    Get Children-list, and then exclude specific childrens

    Hi there,

    I have got a razor macro for a sitemap, which look like this:

    <ul>
        @foreach(var item in Model.Parent.DescendantsOrSelf()){
            <li><href="@item.Url">@item.Name</a></li>
        }
    </ul>

     

    Question 1:

    I want to exclude specific descendants of my list. What to do?

     

    Question 2:

    Right now they're just being listed in one big list, but is it possible to list the descendants and childs like this:

    http://ecigaret-info.dk/sitemap.aspx

     

    I have tried several things from my Google searching for a few hours, and now my patience is up :(

  • BrianAhle 4 posts 34 karma points
    Feb 20, 2013 @ 20:38
    BrianAhle
    0

    I have tried something like this for Question 1:

    var excludedDoctypes new["Teaser bokse""Slide Mappe""Webshop" };

    foreach (var childNode in Model.Parent.DescendantsOrSelf())
    {
      if (!excludedDoctypes.Contains(childNode.NodeTypeAlias))
      {
        <li><href="@childNode.Url">@childNode.Name</a></li>
      }
    }

     

    Totally wrong?

  • Stefan Bohlin 46 posts 168 karma points
    Feb 21, 2013 @ 09:41
    Stefan Bohlin
    0

    It's almost correct. You just need to cast "childNode.NodeTypeAlias" as a string like this:

    if (!excludedDoctypes.Contains((string)childNode.NodeTypeAlias))

  • Stefan Bohlin 46 posts 168 karma points
    Feb 21, 2013 @ 10:05
    Stefan Bohlin
    100

    For your second question i would do like this:

    @GetContentRecursive(Model.Parent)


    @helper GetContentRecursive(dynamic node{
       
      var excludedDoctypes new["Teaser bokse""Slide Mappe""Webshop" };
      
      <ul>
      
          @foreach(var childNode in node.Children){
                          
              if (!excludedDoctypes.Contains((string)childNode.NodeTypeAlias))
              {
                 <li>
                   <href="@childNode.Url">@childNode.Name</a>
                     
                 @if (childNode.Children.Count(0)
                 {
                   @GetContentRecursive(childNode)
                 }
               
                 </li>
              }                                       
              
                                                                 
          }
      </ul>
                                                         
    }

Please Sign in or register to post replies

Write your reply to:

Draft