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
    Oct 30, 2012 @ 17:42
    Fuji Kusaka
    0

    Listing Parent and Child of Child

    Hi guys,

    Am stuck and my drain just stoped working here. I have a folder with some Departement Node Listed where again i  have a list of activities under those dept.

    I kind of stuck here where i need to list those in a ul list. Here is how my content looks like

    -- Folder (Department)
    --- Departement 1
    ---- Activities 1
    ----- Sub Act
    ---- Activities 2
    ----- Sub Act 1
    ----- Sub Act 2
    -- Department 2
    --- Activities 1
    --- Activities 2

     

    The result of this should be something like 

    <ul>
    <li>Department 1
    <ul>
    <li>Activities 1</li>
    <li><a href="subact1.aspx">Sub Act 1</a></li>
    <li><a href="subact2.aspx">Sub Act 2</a></li>
    </ul>
    </li>
    </ul>

    So far here is my code and i got stuck on how to loop the sub content to display subact1.aspx etc

    @using umbraco.MacroEngines;
    @inherits umbraco.MacroEngines.DynamicNodeContext
    @{
       dynamic Sector = Model.NodeById(umbraco.library.GetDictionaryItem("Side Nav"));
        
        
         <ul id="menu">
                @foreach (dynamic item in Sector.Children.Where("Visible"))
                {
                    <li><a href="#">@item.Name</a>
                       @if(item.Children.Count() > 0){
                           <ul>
                            <div class="box @item.sectorStyle"> 
                               <div class="plainTop">
                                  <div class="subMenu">
                                        @foreach(dynamic content in item.Children){
                                            <li class="titsubMenu">@content.Name</li>
                                            
                                            if(content.Children.Count() > 0){
                                            
                                                 foreach (dynamic act in content.AncestorOrSelf("Activities").Children.Where("Visible"))
                                                 {
                                                    <li><a href="@act.Url">@act.name</a></li> 
                                                 }
                                            }
                                        }
                                 </div>
                                 </div>
                            </div>
                           </ul>
                       }
                    </li>
                   <li><div class="@Library.If((item.IsLast()), " ", "sep")"></div></li>
                }
         </ul>
                }

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Oct 30, 2012 @ 19:19
    Tom Fulton
    0

    Hi Fuji,

    On your last loop, not sure why you're using AncestorOrSelf - why not just .Children to get the Children of "content" (which should be the activities node?)

    foreach (dynamic act in content.Children.Where("Visible"))

    Though I guess yours should work anyway.  What are you getting so far?

    -Tom

  • Fuji Kusaka 2203 posts 4220 karma points
    Oct 30, 2012 @ 19:49
    Fuji Kusaka
    0

    Hi Tom,

    I finally got it working making use of Descendants instead.

    @foreach(var page in item.Descendants("Activities")){
                                      <li class="titsubMenu">@page.Name</li>
                                     foreach(var subContent in page.Children){
                                                    <li><a href="@subContent.Url">@subContent.Name</a></li> 
                                      }
                                    }

     

    //fuji

Please Sign in or register to post replies

Write your reply to:

Draft