Copied to clipboard

Flag this post as spam?

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


  • J 351 posts 606 karma points
    Nov 13, 2018 @ 20:57
    J
    0

    Get Nodes/Pages by Document type

    I have a Home node. Under the home node i have a Blogs node and under Blogs i have a Blog node (so Blogs contains a list and Blog is a single blog).

    I add an XSLT by Document Type (standard XSLT that comes with Umbraco) and change the Doc type to "blog" and add this macro to the Home page template so the blogs list displays on the home page - but nothing displays.

    I change it to "blogs" and i get the Blogs link (not the title etc as i would have expected).

    How could i list the blogs on the homepage?

  • Bharani Dharan Jayasuri 12 posts 126 karma points c-trib
    Nov 14, 2018 @ 09:40
    Bharani Dharan Jayasuri
    0

    Hi J,

    I would do this to display a list of blog nodes,

    @{
    var selection = Model.Content.Site().DescendantOrSelf("blogs").Children("blog").Where(x => x.IsVisible()).ToArray();
    }
    
    <ul>
        @foreach(var item in selection){
            <li>
                <a href="@item.Url">@item.Name</a>
            </li>
        }
    </ul>
    

    assuming the document type aliases are "blogs" and "blog" respectively.

  • Harry Spyrou 199 posts 561 karma points
    Nov 14, 2018 @ 14:28
    Harry Spyrou
    1

    Have in mind that Bharani's answer should work, but it's the slowest of all methods.

    It should be fine if you are not loading everything (or a large number of descendants) and you have something like Take(7) in the end but if you're loading thousands it will be slow.

  • 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