Copied to clipboard

Flag this post as spam?

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


  • Keith R Hubbard 175 posts 403 karma points
    Nov 04, 2013 @ 05:30
    Keith R Hubbard
    0

    Get Children of Specific NodeTypeAlias or DocumentTypeAlias V6

    I am trying to list the children page links of a DocumentType GeneralInformaion. The children are just Textpages. I Have tried numerous things with this Partial View and had no luck. This was easy when we had Razor macro engines because I could use NodeByID() not so easy with V6. The General Information is using umbracoNavihide not to be listed in the Nav.

    I have tried

      @foreach (var page in Model.Content.Children.Where("NodeTypeAlias == \"GeneralInformation\"").First.Children) {
    • @page.Name
    • }

    and

      @foreach (var group in Model.Content.Descendants("GeneralInformation").First().Children) { foreach(var item in group) {
    • @item.Name
    • } }

    Please help this is driving me Krazy!!! Most search examples pull XSLT

  • Fuji Kusaka 2203 posts 4220 karma points
    Nov 04, 2013 @ 06:39
    Fuji Kusaka
    2

    Hi keith,

    Could you try something like

    @foreach (var page in Model.Children.Where("NodeTypeAlias == \"GeneralInformation\"").Where("Visible"){
        @page.Children.First().Name
    }
  • Keith R Hubbard 175 posts 403 karma points
    Nov 04, 2013 @ 06:46
    Keith R Hubbard
    0

    I got This

    Parser Error Message: Expected a "{" but found a "var". Block statements must be enclosed in "{" and "}". You cannot use single-statement control-flow statements in CSHTML pages. For example, the following is not allowed:

  • Fuji Kusaka 2203 posts 4220 karma points
    Nov 04, 2013 @ 06:51
    Fuji Kusaka
    1

    Looks like there is a missing closing ")"

    @foreach (var page in Model.Children.Where("NodeTypeAlias == \"GeneralInformation\"").Where("Visible"))
  • Keith R Hubbard 175 posts 403 karma points
    Nov 04, 2013 @ 06:59
    Keith R Hubbard
    0

    Still no luck.

    Compiler Error Message: CS0119: 'Umbraco.Web.PublishedContentExtensions.Children(Umbraco.Core.Models.IPublishedContent)' is a 'method', which is not valid in the given context

    Source Error:

    Line 8:

      Line 9:
      Line 10: @foreach (var page in Model.Children.Where("NodeTypeAlias == \"GeneralInformation\"").Where("Visible")) Line 11: { Line 12:
  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Nov 04, 2013 @ 08:23
    Dennis Aaen
    0

    Hi Keith,

    Have you tried something like this:

    foreach(var page in Model.Children.Where("NodeTypeAlias = @0", "GeneralInformation").Where("Visible")){
       
    @page.Children.First().Name
    }

    Documentation of filtering and lots of more can be found here: http://our.umbraco.org/documentation/reference/querying/DynamicNode/Collections

    Hope this helps you.

    /Dennis

  • Troels Larsen 75 posts 280 karma points
    Nov 04, 2013 @ 21:17
    Troels Larsen
    2

    Hey Mate

    If i read u headline and question correct u jumped on the mvc train and what to know how to filter children based on document type. if so then all u need to do is send regular linq to u where statement instead of the "amputated" string version like so

    @foreach(var child in Model.Content.Children.Where(c => c.DocumentTypeAlias.Equals("GeneralInformation") && c.GetPropertyValue<bool>("umbNaviHideOrWhatEver")))
    {
        <a href="@child.Url">@child.Name</a>
    }
    

    hope that helps :)

  • Keith R Hubbard 175 posts 403 karma points
    Nov 04, 2013 @ 21:33
    Keith R Hubbard
    1

    That resolved the error and actually list the General Information link. It would be nice to list the children below.

        <ul>
      @foreach(var child in Model.Content.Children.Where(c => c.DocumentTypeAlias.Equals("GeneralInformation") && c.GetPropertyValue<bool>("umbracoNaviHide")))
    {
          <li>
            <a href="@child.Url">@child.Name</a>
          </li>
    }
    
    </ul>
    

    How do i get it to list the textpages below general information?

  • Troels Larsen 75 posts 280 karma points
    Nov 04, 2013 @ 22:06
    Troels Larsen
    2

    You iterate over child.Children inside your loop

    <ul>
        @foreach (var child in Model.Content.Children.Where(c => c.DocumentTypeAlias.Equals("GeneralInformation") && c.GetPropertyValue<bool>("umbracoNaviHide")))
        {
            <li>
                <a href="@child.Url">@child.Name</a>
                @if(child.Children.Any(x => x.DocumentTypeAlias.Equals("TextPage")))
                {
                    <ul>
                        @foreach(var page in child.Children.Where(p => p.DocumentTypeAlias.Equals("TextPage")))
                        {
                            <li>
                                <a href="@page.Url">@page.Name</a>
                            </li>
                        }
                    </ul>
                }
            </li>
        }
    </ul>
    
  • Keith R Hubbard 175 posts 403 karma points
    Nov 04, 2013 @ 23:02
    Keith R Hubbard
    1

    That works! Thank you!!! At least on my home page. All other templates it comes up blank. I guess it cannot find the route? do you have any suggestions?

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    
    @{
        Layout = null;
    }
    
    <div class="well">
    <ul>
        @foreach (var child in Model.Content.Children.Where(c => c.DocumentTypeAlias.Equals("GeneralInformation") && c.GetPropertyValue<bool>("umbracoNaviHide")))
        {
            <li>
                <a href="@child.Url">@child.Name</a>
                @if (child.Children.Any(x => x.DocumentTypeAlias.Equals("CWS-Textpage")))
                {
                    <ul>
                        @foreach (var page in child.Children.Where(p => p.DocumentTypeAlias.Equals("CWS-Textpage")))
                        {
                            <li class="">
                                <a href="@page.Url">@page.Name</a>
                            </li>
                        }
                    </ul>
                }
            </li>
        }
    </ul>
    
    </div>
    
  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Nov 05, 2013 @ 00:24
    Jeavon Leopold
    101

    I think you just need to make sure your collection is always selecting the children of your rootnode?

    <ul>
        @foreach (var child in Model.Content.AncestorOrSelf().Children.Where(c => c.DocumentTypeAlias.Equals("GeneralInformation") && c.GetPropertyValue<bool>("umbracoNaviHide")))
        {
            <li>
                <a href="@child.Url">@child.Name</a>
                @if(child.Children.Any(x => x.DocumentTypeAlias.Equals("TextPage")))
                {
                    <ul>
                        @foreach(var page in child.Children.Where(p => p.DocumentTypeAlias.Equals("TextPage")))
                        {
                            <li>
                                <a href="@page.Url">@page.Name</a>
                            </li>
                        }
                    </ul>
                }
            </li>
        }
    </ul>
    
  • Andrew Vennells 16 posts 101 karma points
    Aug 14, 2015 @ 01:07
    Andrew Vennells
    0

    For anybody wanting to do the same but inherit the grid layout from the parent node, this works

    @for (var content = Model.Content; content != null; content = content.Parent)
    {
        @content.GetGridHtml("gridLayout");
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft