Retrieving root node for an unpublished content it...
# help-with-umbraco
c
Hey all, Might be a silly question, building a custom data source for use in the contentment package. Reason being for this custom data source is in a multi root node website, I need to specifically grab items of a type only relative to the current node. I have a working version that correctly does this "entrusting" the current node is published in which I do
Copy code
csharp
     var example = umbracoContext.Content.GetById(currentNode).AncestorOrSelf(1).Descendants<ExampleType>();
However, if the currentNode is unpublished, it then throws an error as it ofcourse doesnt exist in the PublishedCache. Would it be correct to assume this would be an instance where I need to retrieve the root node via the ContentService? Or is there another form of service that wouldnt hit the database, but allow me to traverse upwards from this unpublished node. Thanks!
j
Contentment has a method that gets you the current node or its parents id that you can use in your datalist: https://github.com/leekelleher/umbraco-contentment/blob/develop/docs/editors/data-list.md#accessing-contextual-content
c
Ah yes, I should have added to my original post 😅 - We happen to be using this contentment property type in a block list editor which sadly Lee mentions that the IContentmentContentContext interface doesnt play nicely with: https://github.com/leekelleher/umbraco-contentment/issues/306 I see however this got updated with a patch for Umbraco 13, so I just need to figure out a patch for 11.5 / 12.x!
3 Views