Copied to clipboard

Flag this post as spam?

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


  • Accusoft 58 posts 109 karma points
    Aug 23, 2012 @ 16:37
    Accusoft
    1

    Getting All Content Nodes of Particular Document Type

    I've seen some samples of how to accomplish this in XSLT, was wondering if anyone had a snippet for how to handle it in Razor?  I just want to get a list of all nodes with a particular document type and loop through them displaying the names.

  • gilad 185 posts 425 karma points
    Aug 23, 2012 @ 16:45
    gilad
    1

    Hii Chris.

    Try this : 

    @Model.AncestorOrSelf().Descendants("nodeTypeAlias")

  • Accusoft 58 posts 109 karma points
    Aug 23, 2012 @ 17:42
    Accusoft
    0

    Hi gilad,

    Thanks for the reply!

    How do I loop through the resulting nodes?

    I've tried:

    var productNodes = @Model.AncestorOrSelf().Descendants("Product");

    foreach (var productNode in productNodes)
    {
    @productNode.Name<br />
    }

    but it's throwing an error.

  • gilad 185 posts 425 karma points
    Aug 23, 2012 @ 17:46
    gilad
    0

    Hii, sorry.

    Add .Items to first line :

    var productNodes =@Model.AncestorOrSelf().Descendants("Product").Items;
  • jonok 297 posts 658 karma points
    Feb 13, 2014 @ 02:15
    jonok
    0

    Is there a way to return all nodes except for a certain document type? eg.

    var nodes =@Model.AncestorOrSelf().Descendants("not Product").Items;
  • Fuji Kusaka 2203 posts 4220 karma points
    Feb 13, 2014 @ 06:57
    Fuji Kusaka
    0

    You could eventually do something like  this 

    var c = new DynamicNode(1024).GetChildrenAsList.Items.Where(x=>x.GetProperty("umbracoNaviHide").Value != "1" && x.NodeTypeAlias !="docType");

    Hope this helps

    //fuji

     

  • Thomas 319 posts 606 karma points c-trib
    Oct 20, 2017 @ 08:28
    Thomas
    0

    in 7.7.2

    var names = Model.Content.AncestorOrSelf(1).Descendants("doctypealias")
    
    foreach (var name in names)
    {
        <p>@name.Id</p>
        <p>@name.Name</p>
    }
    
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies