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
    May 05, 2012 @ 08:45
    Fuji Kusaka
    0

    List SubPages By Level

    Hi All,

    I have a Sub Navigation which triggers only when am on level 4 of my content section.

    So lets say i have subPages under any Node on Level 4 it should display.

    However for some reason when am on particular page of level 3 it gives me this error and some other level 3 pages no error!!

    Error loading MacroEngine script (file: subpages[razor].cshtml) 

    @using umbraco.MacroEngines;
    @{
     
        var subPage Model.AncestorOrSelf(4);
        const string selectedClass " class=\"current\"";
     
             
        foreach(var page in subPage.Children.Where("Visible")){    
                                                    <href="@page.Url" title="@page.Name">@page.Name</a>  
          
           }
      }

    Any thgoughts??

    //fuji

  • Sobin 25 posts 46 karma points
    May 14, 2012 @ 19:41
    Sobin
    0

    Hey, I dont know wats wrong with that code.  You should try this code.....                                                                                                                                        @foreach (var page in Model.AncestorOrSelf(4).Children.Where("Visible"))
    {
       if (page.Children.Where("Visible").Count() > 0)
       {
             @foreach (var subpage in page.Children.Where("Visible"))
             {
                <a href="@subpage.Url">@subpage.Name</a>
             }
       }
    }
                                                                                                                                               

  • Fuji Kusaka 2203 posts 4220 karma points
    May 14, 2012 @ 22:44
    Fuji Kusaka
    0

    Hi Sobin,

    I forgot to update this post, yes i got it working already. What was missing in my code was a if statement to check wherever their are more nodes under Level 4.

    If Yes displays them, but at some point when am on Level 4 my razor script would triggers me some errors since no check is being done before displaying the ancestors. 

    @using umbraco.MacroEngines;
    @inherits umbraco.MacroEngines.DynamicNodeContext

    @{
     
     var parent Model.AncestorOrSelf(4);  
      const string selectedClass " class=\"current\"";
        
      if(parent !=null){
                       <ul id="subPage">
                       @foreach(var item in parent.Children.Where("Visible")){
                               <li@Library.If(item.IsAncestorOrSelf(Model)selectedClass)><href="@item.Url">@item.Name</a></li>
                      }
                        </ul>
           }
      
    }

    //fuji

Please Sign in or register to post replies

Write your reply to:

Draft