Copied to clipboard

Flag this post as spam?

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


  • Jon Frederiksen 50 posts 109 karma points
    Dec 06, 2019 @ 16:40
    Jon Frederiksen
    0

    Current page from partial view

    I'm sure there is an easy answer, but all I found so far is this discussion and it does not help in my case.

    I need to get the current page from a partial view, that @inherits Umbraco.Web.Mvc.UmbracoViewPage<DownloadBox> and which is called from another partial view. Usually no problem to solve this, but in my case the content rendered in this partial view comes from another content tree in Umbraco (Boxes, see the picture).

    I need to know if the current page is descended of Home or another item bellow Home.

    I hope it makes sense and that someone can point me into the right direction.

    Cheers

    / Jon

    enter image description here

  • Marc Goodson 1718 posts 11411 karma points MVP 7x c-trib
    Dec 07, 2019 @ 11:31
    Marc Goodson
    101

    Hi Jon

    I think you should be able to access the IPublishedContent item attached to the current Umbraco Helper or indeed the current Umbraco Context, these should be unaltered by which 'Model' you pass through to your PartialView.

    See what the values are for the following in your partial view for:

           <h2>@Umbraco.AssignedContentItem.Name</h2> <h3>@UmbracoContext.PublishedRequest.PublishedContent.Name</h3>
    

    These should be the name of the Page that was originally requested rather than the name of the picked download box.

    Then it's a case of determining if your page is directly below home...

    You can then either look at the 'Level' property of your current page, this gives the depth of the current item in the content tree, so anything with a Level > 1 will not be directly underneath home or you can ook into the current Path property of the item to see if it contains the id of one of the subpages, (the Path property is present on all Umbraco IPublishedContent items and gives a list in order of all the ids of the ancestor nodes for your published content item) or you can use AncestorsOrSelf and see if a particular page is present in the Ancestory...

    regards

    Marc

  • Jon Frederiksen 50 posts 109 karma points
    Dec 07, 2019 @ 16:26
    Jon Frederiksen
    0

    Hi Marc

    The winner is @UmbracoContext.PublishedRequest.PublishedContent :-)

    It gives me the item that originated the request and located under the item in question.

    Thank you very much.

    / Jon

Please Sign in or register to post replies

Write your reply to:

Draft