Copied to clipboard

Flag this post as spam?

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


  • Roger Withnell 128 posts 613 karma points
    Jul 14, 2015 @ 16:55
    Roger Withnell
    0

    Get the children from the node id

    In a Partial Macro, I have the CurrentPage.Id

    How do I get to the child pages of this Id?

    Your help would be much appreciated.

    Thanking you in anticipation.

    Roger

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jul 14, 2015 @ 18:36
    Dennis Aaen
    101

    Hi Roger,

    If it´s a specific id that you want to display the children of then you can do like that by using a UmbracoHelper for the dynamic Razor

    @{
        var page = Umbraco.Content(1234);
    }
    
    <h3>@page.PropertyAlias</h3>
    
    @foreach (var child in page.Children) { 
        <a href="@child.Url">@child.Name</a>
    }
    

    For the strongly typed Razor model you need to do it like this

    @{
        var page = Umbraco.TypedContent(1234);
    }
    
    <h3>@page.GetPropertyValue<string>("propertyAlias") 
    </h3>
    
    @foreach (var child in page.Children) { 
        <a href="@child.Url">@child.Name</a>
    }
    

    The documentation for the UmbracoHelpers can be found here https://our.umbraco.org/documentation/Reference/Querying/UmbracoHelper/

    If is not a specific id but just CurrentPage, then you can do it like this.

    @foreach (var child in page.Children) { 
        <a href="@child.Url">@child.Name</a>
    }
    

    Hope this helps,

    /Dennis

  • Roger Withnell 128 posts 613 karma points
    Jul 15, 2015 @ 13:44
    Roger Withnell
    0

    Thanks for this, Dennis.

    Actually I discovered that

    @foreach (var child in CurrentPage.Children) {
    }
    

    worked for me.

    I'm very frustrated that I have to ask these very basic questions. Over the last 10 years I've built my own CMS's, one in Classic ASP and the other in ASP.NET using VB and WebForms. Now I've chosen Umbraco as the platform to which to convert all my customers. Perhaps switching to C# and MVC at the same time is part of my problem? I have been through all the videos on Umbraco.tv, some of them more than once.

    For example, with the problem above, I wanted to know all the properties I can use with CurrentPage like .ID, .Site, .Url etc. I'm using Visual Studio 2013 and there is no intellisense for CurrentPage. Can I set this up? Otherwise, where do I find a reference to CurrentPage that lists all the properties?

    I very keen to get my head around Umbraco. What else do you recommend I do? Perhaps if I was an expert in MVC I wouldn't be experiencing these issues?

    I would much appreciate your comments.

    Roger

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jul 15, 2015 @ 18:17
    Dennis Aaen
    1

    Hi Roger,

    Don´t be sad about asking very basic questions, we are a very friendly community that are more than happy to help new people to get started with Umbraco.

    We also help each other. Yes if you could learn ASP.NET and MVC then I think you will be good to understand Umbraco CMS. And then I can also recommend the Umbraco TV site, but this you already know.

    To get intellisense in Visual Studio you will need to use the strongly typed version of Umbraco where CurrentPage is Model.Content

    So if you for instance writes:

    Model.Content.Id 
    

    You will get the current page id. One more thing I think can help you maybe could be these Razor cheat sheets, there is one for the dynamic version of Razor where current page is CurrentPage and there is also the strongly typed version where current page is Model.Content.

    https://our.umbraco.org/projects/developer-tools/umbraco-v6-mvc-razor-cheatsheets

    I know this says for Umbraco v6, but you can also use them if you are using a Umbraco version 7.x.x

    Hope this helps and make sense, and remember don´t be afraid to ask questions in here even if you think they are to basic. No questions is to basic to be asked in here.

    /Dennis

  • Roger Withnell 128 posts 613 karma points
    Jul 19, 2015 @ 16:32
    Roger Withnell
    0

    Thanks, Dennis, and the cheat sheets are very helpful.

    Your advice has help me fix the current problem and I'm taking some time to get my head around MVC.

    Much appreciated.

    Roger

Please Sign in or register to post replies

Write your reply to:

Draft