Reputation: 1
I have upgraded an Umbraco 7 CMS to Umbraco 13.
As part of my custom search endpoint I need to return a path, but the path property returns only a negative number as a string. eg. -1,1440,5787. This is everywhere i use Ubraco Helper. In the Umbraco UI i can see the correct path.
Here is my code for one of the locations, i can work around it everywhere else.
IEnumerable<IPublishedContent> basisSideContentNodes = _umbracoHelper.ContentAtRoot().SelectMany(root => root.DescendantsOrSelfOfType("BasisSide"));
basisSideNodes = basisSideContentNodes
.Where(node => node.Name.ToLower().Contains(query.SearchTerm.ToLower()) ||
node.Value<string>("tekst").ToLower().Contains(query.SearchTerm.ToLower()))
.Select(node => new SearchResult
{
Id = node.Id,
Name = node.Name,
Content = node.Value<string>("tekst"),
Path = $"/{node.Path}"
}).ToList();
Please help me. Is there a way to get the path on the backend?
I expected it to return a string with the path to the node.
Upvotes: 0
Views: 40
Reputation: 2316
To clarify what's going on here:
The value of the Path property on an Umbraco Content node is actually a comma-delimited list of the path hierarchy for that particular content node.
All content starts at the Content root (-1), and is in a tree hierarchy, so you can use the path to determine the position in the tree of a particular node identified by the content Ids of each ancestor.
Similarly, nodes in the Media tree structure have the same property, starting with -1 representing the Media root node.
As you have discovered, to retrieve the Url for a content node, you need to use the Url()
extension method - under the hood, Umbraco is going through a series of "Content Finders" to determine the url for a specific node based on the request (for example, to determine the domain) and the position of the node in the tree.
It's also worth exploring the parameters to the Url()
extension - some of this includes the ability to return a fully qualified Url (by default you will get a root-relative url - e.g. /tekst/).
Upvotes: 0
Reputation: 1
Turns out there is a URL method on IPublishedContent. IPublishedContent Documentation
basisSideNodes = basisSideContentNodes
.Where(node => node.Name.ToLower().Contains(query.SearchTerm.ToLower()) ||
node.Value<string>("tekst").ToLower().Contains(query.SearchTerm.ToLower()))
.Select(node => new SearchResult
{
Id = node.Id,
Name = node.Name,
Content = node.Value<string>("tekst"),
Path = node.Url()
}).ToList();
Upvotes: 0