Replacement for IPublishedCache.GetAtRoot()

In v15/v16 IPublishedCache.GetAtRoot(string?) is obsolete and suggest using IDocumentNavigationQueryService instead.

It seems to return root keys, which I guess should be used to lookup instead.

It seems we can also use ContentAtRoot() from IPublishedContentQuery but unfortunately it didn’t support culture as the underlying GetAtRoot() : Allow `ContentAtRoot()` to accept culture by bjarnef · Pull Request #20129 · umbraco/Umbraco-CMS · GitHub

It seems there are a few different other options:

  • Use GetByIdfrom IPublishedContentCache as Andy’s example here: URL Segment Customisation with Umbraco 15.4
    It seems it need to do multiple lookups though - not sure why an GetByIds() isn’t available?
  • Use Content() from IPublishedContentQuery which support multiple ids.
  • Use ContentAtRoot() from IPublishedContentQuery which isn’t obsolete, but doesn’t support requesting a specific culture as the old GetAtRoot()

What are best practice to get root node(s) without knowing ids?

I’ve just run into this issue (specifically as part of @prjseal ‘s Clean package - authors.cshtml).

Was the solution to use IDocumentNavigationQueryService instead, as per this PR thread?

Something like:

@inject Umbraco.Cms.Core.IPublishedContentQuery publishedContentQuery

@{
    AuthorList? authorList = publishedContentQuery?.ContentAtRoot()?.DescendantsOrSelf<AuthorList>()?.FirstOrDefault();
}

TIA!

Hi Rich
I’ve got this fixed in Clean now, just need to push an update.

Just gonna test it out and deploy the latest version.

Will comment here and let you know.

Kind regards

Paul

1 Like

Yes, I submitted the PR to make it query culture specific content and simpler to migrate, if the method were used. Basically just a wrapper for the underlying ContentAtRoot() from IPublishedCache used in IPublishedContentQuery.

Do you know if this ever made it into V17. I’ve read through the PR, but that looks to be fixing V13.

I’m trying to get a node at the Root level, but with a specific culture.

It doesn’t seem to.

Umbraco 16:

Umbraco 17:

Yeah, and UmbracoHelper.ContentAtRoot is also missing the culture :frowning: