Copied to clipboard

Flag this post as spam?

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


  • Anders Schmidt 76 posts 207 karma points
    Nov 26, 2013 @ 21:32
    Anders Schmidt
    0

    List child and child-child together

    I have a menu structure like this:

     

    level1

    level1

      level2

      level2

         level3

         level3

    level1

    I would like to create menu with only 2 levels from this structure. (print out level2 and level3 together).

    To explain somthing like this.

    <ul>                   
    @foreach (var page in home.Children.Where("Visible"))
        {
              <li><a href="@page.Url">@page.Name</a>
                  @if (page.Children.Where("Visible").Count() > 0)
                      {
                        <ul>
                           @foreach (var subpage in page.Children.Where("Visible"))
                            {
                              <li><a href="@subpage.Url">@subpage.Name</a></li>
                              @foreach (var subsubpage in page.Children.Where("Visible"))
                               {
                                <li><a href="@subsubpage.Url">@subsubpage.Name</a></li>
                                   } }
                      </ul>
    
             </li>
        }                    
    </ul>             

    Thanks in advance.

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Nov 26, 2013 @ 21:48
    Jeavon Leopold
    0

    Hi Anders, I think you have only one issue in your snippet, try this:

    <ul>                   
    @foreach (var page in home.Children.Where("Visible"))
        {
              <li><a href="@page.Url">@page.Name</a>
                  @if (page.Children.Where("Visible").Count() > 0)
                      {
                        <ul>
                           @foreach (var subpage in page.Children.Where("Visible"))
                            {
                              <li><a href="@subpage.Url">@subpage.Name</a></li>
                              @foreach (var subsubpage in subpage.Children.Where("Visible"))
                               {
                                <li><a href="@subsubpage.Url">@subsubpage.Name</a></li>
                                   } }
                      </ul>
    
             </li>
        }                    
    </ul>             
    
  • Anders Schmidt 76 posts 207 karma points
    Nov 26, 2013 @ 22:00
    Anders Schmidt
    0

    Thanks. I am still getting error.

    This will work. But it will not become propper html....

                  @{var home = Model.AncestorOrSelf(1);}
                    <ul id="step2">                 
                        @foreach (var page in home.Children.Where("Visible"))
                        {
                              <li><a href="@page.Url">@page.Name</a>
                                   @if (page.Children.Where("Visible").Count() > 0)
                                   {
                                      <ul>
                                         @foreach (var subpage in page.Children.Where("Visible"))
                                         {
                                            <li><a href="@subpage.Url">@subpage.Name</a>
    
                                          @foreach (var subsubpage in subpage.Children.Where("Visible"))
                                            {
                                            <li><a href="@subsubpage.Url">@subsubpage.Name</a></li>
                                            }
                                          </li>
                                         }                               
                                      </ul>
                                   }
                               </li>
                        }       
                    </ul>  
  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Nov 26, 2013 @ 22:05
    Jeavon Leopold
    0

    Just move your li?

              @{var home = Model.AncestorOrSelf(1);}
                <ul id="step2">                 
                    @foreach (var page in home.Children.Where("Visible"))
                    {
                          <li><a href="@page.Url">@page.Name</a>
                               @if (page.Children.Where("Visible").Count() > 0)
                               {
                                  <ul>
                                     @foreach (var subpage in page.Children.Where("Visible"))
                                     {
                                        <li><a href="@subpage.Url">@subpage.Name</a></li>
    
                                      @foreach (var subsubpage in subpage.Children.Where("Visible"))
                                        {
                                        <li><a href="@subsubpage.Url">@subsubpage.Name</a></li>
                                        }
    
                                     }                               
                                  </ul>
                               }
                           </li>
                    }       
                </ul>  
    
  • Anders Schmidt 76 posts 207 karma points
    Nov 26, 2013 @ 22:10
    Anders Schmidt
    0

    Thanks for quick reply.But.

    Moving li gives error: Error loading MacroEngine script (file: ) 

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Nov 26, 2013 @ 22:24
    Jeavon Leopold
    100

    Ah yes, you will need to remove the @ from the second loop,

          @{var home = Model.AncestorOrSelf(1);}
            <ul id="step2">                 
                @foreach (var page in home.Children.Where("Visible"))
                {
                      <li><a href="@page.Url">@page.Name</a>
                           @if (page.Children.Where("Visible").Count() > 0)
                           {
                              <ul>
                                 @foreach (var subpage in page.Children.Where("Visible"))
                                 {
                                    <li><a href="@subpage.Url">@subpage.Name</a></li>
    
                                  foreach (var subsubpage in subpage.Children.Where("Visible"))
                                    {
                                    <li><a href="@subsubpage.Url">@subsubpage.Name</a></li>
                                    }
    
                                 }                               
                              </ul>
                           }
                       </li>
                }       
            </ul>  
    
  • Anders Schmidt 76 posts 207 karma points
    Nov 26, 2013 @ 22:32
    Anders Schmidt
    0

    Of course!!!! Thanks.

Please Sign in or register to post replies

Write your reply to:

Draft