Copied to clipboard

Flag this post as spam?

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


  • Kyle Goulding 30 posts 192 karma points
    Jun 15, 2016 @ 14:29
    Kyle Goulding
    0

    How to call Children() not descendants()?

    I have a structure like below

    Page One

    -- Folder

    --- CatOne (tiles)

    --- CatTwo (tiles)

    Page Two

    --Folder

    ---CatOneB (tiles)

    ---CatTwoB (tiles)

    I am using a partial view to pull in the contents of the folders which is the child element of the node, to display on 'Page One' and 'Page Two' but it is pulling through all 4 (tiles) when I am calling the partial view.

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
        var root = Model.Content;
        var tiles = root.Descendants("tiles");
    
        if(tiles.Count() > 0)
        {
            <div class="row tile-row">
                @foreach(var node in tiles)
    
                {
                    <div class="col-md-3">
                        <div class="tile">
                            <h3>@(node.GetPropertyValue("tileTitle"))</h3>
                            @(node.GetPropertyValue("tileBodyText"))<br/>
                            <a class="btn btn-more" href="@(node.GetPropertyValue("tileButtonLink"))">@(node.GetPropertyValue("tileButtonText"))</a>
                        </div>  
                    </div>
                }
            </div><!--/.row-->
        }
    }
    

    I think it is because I am using descendants instead of children but I am unsure of how to change this...Can someone help me with using Children() instead of descendants.

    Thanks

  • Alex Skrypnyk 6150 posts 24110 karma points MVP 8x admin c-trib
    Jul 18, 2016 @ 21:18
    Alex Skrypnyk
    0

    Hi Kyle,

    Did you solve your problem?

    Read documentation about traversing in Umbraco

    https://our.umbraco.org/documentation/reference/templating/mvc/querying

    If you want children nodes:

    //dynamic access
    @CurrentPage.Children.Where("Visible")
    
    //strongly typed access
    @Model.Content.Children.Where(x => x.IsVisible())
    

    Thanks,

    Alex

  • Kyle Goulding 30 posts 192 karma points
    Jul 19, 2016 @ 07:49
    Kyle Goulding
    101

    Hi Alex,

    Thank you - yes I did manage to get it working using the below -

    CurrentPage.FirstChild("Folder").Children("tiles").Where("Visible");
    

    To look at the first child of document type folders and then looked for the children of that doc type to get the tiles.

  • Alex Skrypnyk 6150 posts 24110 karma points MVP 8x admin c-trib
    Jul 19, 2016 @ 11:09
    Alex Skrypnyk
    0

    Great, Kyle!

    Mark topic as solved if it is, it will be better for other developers who have the same problem.

Please Sign in or register to post replies

Write your reply to:

Draft