Copied to clipboard

Flag this post as spam?

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


  • k 256 posts 654 karma points
    Aug 08, 2017 @ 06:38
    k
    0

    Display nodes from parent at second level

    Hello,

    I need to display nodes from parents at second level in umbraco 7.6.

    Can someone please help.

    Regards,

    kusum

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Aug 08, 2017 @ 08:34
    Dennis Aaen
    0

    Hi kusum,

    Would it be possible for you to share a screenshot of you content tree of the pages that you want to display?

    And also let us know on which page you want the data to be outputted.

    Best,

    /Dennis

  • k 256 posts 654 karma points
    Aug 08, 2017 @ 09:28
    k
    0

    Hello Denis,

    Config
       EN
         Page one
             sub page 1
                  Sub 1.1
                  Sub 1.2
             sub page 2
                  Sub 2.1
                  Sub 2.2
    

    When I am in page sub page 1, the menu should have the values sub page 1 and sub page 2.

    The menu should be same when I am in the page sub 1.1. that is menu should have the values sub page 1 and sub page 2.

    Please let me know if I am not clear.

    Thanks,

    kusum

  • Paul Seal 524 posts 2889 karma points MVP 6x c-trib
    Aug 08, 2017 @ 09:06
    Paul Seal
    0

    Hi Kusum

    The best way to do this is to find the parent you are interested in by document type alias.

    Home page

    IPublishedContent homePage = Model.Content.AncestorOrSelf("Home");
    

    Blog list page

    IPublishedContent blog = Model.Content.AncestorOrSelf("Blog");
    

    See this link for more details. http://www.codeshare.co.uk/blog/how-to-find-the-home-page-in-umbraco/

    Cheers

    Paul

  • k 256 posts 654 karma points
    Aug 08, 2017 @ 09:29
    k
    0

    Hello Paul,

    But what if the parent is not the same everytime ?

    Regards,

    kusum

  • Paul Seal 524 posts 2889 karma points MVP 6x c-trib
    Aug 08, 2017 @ 09:32
    Paul Seal
    0

    Then you can use:

    Model.Content.AncestorOrSelf(2);
    

    Just change the number accordingly for the correct level.

  • k 256 posts 654 karma points
    Aug 08, 2017 @ 09:40
    k
    0

    Tried and getting error :

    Compiler Error Message: CS1579: foreach statement cannot operate on variables of type 'Umbraco.Core.Models.IPublishedContent' because 'Umbraco.Core.Models.IPublishedContent' does not contain a public definition for 'GetEnumerator'
    
  • Paul Seal 524 posts 2889 karma points MVP 6x c-trib
    Aug 08, 2017 @ 09:45
    Paul Seal
    0

    What is at the top of your view?

    Have you got?

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    

    Try putting this somewhere in the view to render out the name.

    @Model.Content.AncestorOrSelf(2).Name
    
  • Paul Seal 524 posts 2889 karma points MVP 6x c-trib
    Aug 08, 2017 @ 09:46
    Paul Seal
    100

    In a partial view you do it like this:

    @inherits UmbracoViewPage
    
    @Umbraco.AssignedContentItem.AncestorOrSelf(2).Name
    
  • k 256 posts 654 karma points
    Aug 08, 2017 @ 09:59
    k
    0

    working. Thanks :)

  • Paul Seal 524 posts 2889 karma points MVP 6x c-trib
    Aug 08, 2017 @ 10:40
    Paul Seal
    0

    Great, please click on 'mark as solution' for the one which helped you get it working.

Please Sign in or register to post replies

Write your reply to:

Draft