Copied to clipboard

Flag this post as spam?

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


  • René Andersen 238 posts 684 karma points
    May 20, 2015 @ 11:15
    René Andersen
    0

    Show all children from different categories

    Hi,

    I have this structure on my site:

    -- Home
       -- Cast & Crew (doctype: Portfolio)
         -- Cast (doctype: PortfolioType)
             -- Child 1
             -- Child 2
         -- Crew (doctype: PortfolioType)
             -- Child 1
             -- Child 2
         -- Scenes (doctype: PortfolioType)
             -- Child 1
             -- Child 2

    Child 1 + 2 can have different doctypes.

    My problem is that I can't figure out how to show all children under (Cast, Crew, Scenes) my code only render out the children from the first category (Cast).

    My code looks like this:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage

    @{
    var portfolio = CurrentPage.Down(1);
    }

    <section class="module pb-0">
    <ul id="works-grid" class="works-grid works-grid-masonry [email protected]("imagesRow") works-hover-w">
    @foreach (var item in portfolio.Children)
    {
    <li class="work-item @item.Parent.Name">
    <a href="@item.Url">
    <div class="work-image">
    <img src="@item.thumbnail" alt="">
    </div>
    <div class="work-caption font-alt">
    <h3 class="work-title">@item.title</h3>
    <div class="work-descr">
    @item.Parent.Name
    </div>
    </div>
    </a>
    </li>
    }
    </ul>
    </section>

     

    Thanks in advance!

    // René

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    May 20, 2015 @ 11:19
    Dennis Aaen
    100

    Hi René,

    When you want the children and grandchildren of an item you can use the Descendants(); method. And I assume that you content is structured so the items in children under your home item.

    If so then I think something like this should work for you, if the item has it own document type.

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    
    @{
        var portfolio = CurrentPage.AncestorOrSelf(1).Children("DocumentTypeAlias").First();
        var descendants = portfolio.Descendants();
    
    }
    
    <section class="module pb-0">
            <ul id="works-grid" class="works-grid works-grid-masonry [email protected]("imagesRow") works-hover-w">
                @foreach (var item in descendants.Where("Visible"))
                {
                    <!-- Portfolio item start -->
                    <li class="work-item @item.Parent.Name">
                        <a href="@item.Url">
                            <div class="work-image">
                                <img src="@item.thumbnail" alt="">
                            </div>
                            <div class="work-caption font-alt">
                                <h3 class="work-title">@item.title</h3>
                                <div class="work-descr">
                                    @item.Parent.Name
                                </div>
                            </div>
                        </a>
                    </li>
                    <!-- Portfolio item end -->
                }
            </ul>
    </section>
    

    Remember to change the "DocumentTypeAlias" so it match your case.

    Hope this helps,

    /Dennis

  • René Andersen 238 posts 684 karma points
    May 20, 2015 @ 12:11
    René Andersen
    0

    Hi Dennis,

    Once again you solved my problem. Very nice solution.

    Thank you!

    // René

Please Sign in or register to post replies

Write your reply to:

Draft