Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
How can i get parent .. parent till four node of current node in razor ?
I am using like this
var pageId = umbraco.uQuery.GetCurrentNode().Id; var node = new Node(pageId);
node = node.Parent.Parent.Parent.Parent;
But is there any better way to use parent by it's type
Thanks
Hi
it depends a bit on what you do, if you get the typed version of a node using Model.Content you can get the level and then go four higher?
Model.Content
var parentFour = Model.Content.Ancestor(Model.Content.Level - 4);
but this has risks (if you are less than 4 deep - you will be asking for a negative level.
if you parent 4 up has it's own doctype you can ask for the first ancestor that has that
var parentType = Model.Content.Ancestor("Parent4Type");
Thanks for replying on this
I have done like this finally
var nodes = uQuery.GetCurrentNode().GetAncestorOrSelfNodes().Where(x => x.NodeTypeAlias == "alias");
Manish
Just remember that uQuery is obsolete.
Read more here: https://our.umbraco.org/forum/developers/api-questions/45777-uQuery-vs-Examine-vs-IPublishedContent-for-Querying
Thanks,
Oleksandr Skrypnyk
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Get parent of parent .. parent of current node
How can i get parent .. parent till four node of current node in razor ?
I am using like this
var pageId = umbraco.uQuery.GetCurrentNode().Id; var node = new Node(pageId);
node = node.Parent.Parent.Parent.Parent;
But is there any better way to use parent by it's type
Thanks
Hi
it depends a bit on what you do, if you get the typed version of a node using
Model.Content
you can get the level and then go four higher?but this has risks (if you are less than 4 deep - you will be asking for a negative level.
if you parent 4 up has it's own doctype you can ask for the first ancestor that has that
Thanks for replying on this
I have done like this finally
Manish
Just remember that uQuery is obsolete.
Read more here: https://our.umbraco.org/forum/developers/api-questions/45777-uQuery-vs-Examine-vs-IPublishedContent-for-Querying
Thanks,
Oleksandr Skrypnyk
is working on a reply...