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.
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:
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...
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
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:
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
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
is working on a reply...