Copied to clipboard

Flag this post as spam?

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


  • Victor Foster 8 posts 69 karma points
    Sep 13, 2016 @ 13:16
    Victor Foster
    0

    Get all content childer from folder

    Hello,

    I'm fairly new to Umbraco 7, so I apologize if this is staring the me in the face.

    I have a content folder that I'd like to get all of the content items underneath of this within a template. What is the best way to do this?

    The template I am using for the content folder is inheriting from Umbraco.Web.Mvc.UmbracoTemplatePage.

    Thanks!

  • Ivan Ponomarenko 20 posts 105 karma points
    Sep 13, 2016 @ 13:42
    Ivan Ponomarenko
    101

    Hi Victor,

    You can use this code to get typed objects:

    IEnumerable<IPublishedContent> descs = Model.Content.Descendants(); // returns all descendants from all levels under content node
    IEnumerable<IPublishedContent> children = Model.Content.Children; // returns children only under content node
    

    for more information https://our.umbraco.org/Documentation/Reference/Querying/IPublishedContent/Collections

    Regards, Ivan

  • Victor Foster 8 posts 69 karma points
    Sep 13, 2016 @ 17:15
    Victor Foster
    0

    Thanks Ivan! That's super helpful

  • Ivan Ponomarenko 20 posts 105 karma points
    Sep 14, 2016 @ 09:40
    Ivan Ponomarenko
    0

    Glad to help you! welcome to Umbraco :)

    Regards, Ivan

Please Sign in or register to post replies

Write your reply to:

Draft