Using umbraco 6.1.6. Its multilingual site, in some of the sites we have multi region eg Belgium so we have structure below please note there are more pages in each region but i am only showing products and this is where i am having an issue with GetByRoute.
BE
FR
- Products
NL
- Products
the top level be is just holding category in this instance it has no domain assigned, the fr and nl are actual root site nodes and have domains set in umbraco. So for NL we have domain
somesite/be-nl (nl-BE)
when you hit that url you get the home page and all good. You can also hit the products page so
somesite/be-nl/products/
again all good. On that page we have some links that point a products search results page, they look like
somesite/be-nl/products/search/29836-multipurpose/ (search is of type ProductResults the rest of the url does not exist the id part of url is node id to a tag which is a product category)
for the target page of type ProductResults there is content finder implemented,
/// <summary>
/// Tries to find the content item for product search results
/// </summary>
/// <param name="contentRequest">
/// The content request.
/// </param>
/// <returns>
/// True if found
/// </returns>
public bool TryFindContent(PublishedContentRequest contentRequest)
{
if (contentRequest != null)
{
var path = contentRequest.Uri.GetAbsolutePathDecoded();
var parts = path.GetSectionsFromUriAbsolutePath().Distinct(StringComparer.InvariantCultureIgnoreCase).ToList(); //just splits on /
string finalPath = string.Empty;
if (parts.Count > 2)
{
// Parse the path 2 levels deep
var level2Path = string.Concat('/', string.Join("/", parts.Take(2)), '/');
finalPath = level2Path;
// See if there is a node at this path, and its of type ProductResults
var productResultsNode = contentRequest.RoutingContext.UmbracoContext.ContentCache.GetByRoute(level2Path);
if (NoProductResultsNodeFound(productResultsNode))
{
//try with a level 3 path becuase it may be site like hk-en and hk-zh so its 3 levels
var level3Path = string.Concat('/', string.Join("/", parts.Take(3)), '/');
productResultsNode = contentRequest.RoutingContext.UmbracoContext.ContentCache.GetByRoute(level3Path);
finalPath = level3Path;
if (NoProductResultsNodeFound(productResultsNode))
{
return false;
}
}
// OK - we know its a product results page - but we cannot simply return by route as it will return the first match of /products/search found in the tree
// Lets current sites, root node and get the Descendants of type ProductResults
// And return the first one that contains the original content request's level 2 Path in its Url (e.g. /products/search)
var productSearchNode = contentRequest.RoutingContext.UmbracoContext.ContentCache
.GetById(contentRequest.Domain.RootNodeId)
.Descendants(ProductResults.Alias)
.FirstOrDefault(x => x.Url.IndexOf(finalPath) >= 0);
if (productSearchNode == null)
return false;
contentRequest.PublishedContent = productSearchNode;
}
return contentRequest.PublishedContent != null;
}
return false;
}
the route to get item is /be-nl/products/ when you hit this page directly you get a page, in the properties section under alternative links we have /be-nl/products/ however when you do
Quick (so might not be correct by anyway): a route is "/path/to/page" when there is no domain, and "123/path/to/page" when there is a domain, and then 123 is the ID of the node which is the root of the domain. In your case, you probably want a route such as "123/be-nl/products" where 123 is the ID of the "NL" node. Making sense?
Just in case anyone else is having the same issue, Stephen's response is correct. It appears that you need to pass in the root node id of the domain to find the node you want.
GetByRoute in multilingual site
Guys,
Using umbraco 6.1.6. Its multilingual site, in some of the sites we have multi region eg Belgium so we have structure below please note there are more pages in each region but i am only showing products and this is where i am having an issue with GetByRoute.
BE
FR
- Products
NL
- Products
the top level be is just holding category in this instance it has no domain assigned, the fr and nl are actual root site nodes and have domains set in umbraco. So for NL we have domain
somesite/be-nl (nl-BE)
when you hit that url you get the home page and all good. You can also hit the products page so
somesite/be-nl/products/
again all good. On that page we have some links that point a products search results page, they look like
somesite/be-nl/products/search/29836-multipurpose/ (search is of type ProductResults the rest of the url does not exist the id part of url is node id to a tag which is a product category)
for the target page of type ProductResults there is content finder implemented,
the route to get item is /be-nl/products/ when you hit this page directly you get a page, in the properties section under alternative links we have /be-nl/products/ however when you do
you do not get a page and therefore a 404. Any ideas what is going on here?
Quick (so might not be correct by anyway): a route is "/path/to/page" when there is no domain, and "123/path/to/page" when there is a domain, and then 123 is the ID of the node which is the root of the domain. In your case, you probably want a route such as "123/be-nl/products" where 123 is the ID of the "NL" node. Making sense?
Just in case anyone else is having the same issue, Stephen's response is correct. It appears that you need to pass in the root node id of the domain to find the node you want.
So, from the example above, this becomes...
This is what I used and it seems to be easier to retrieve the current website root node:
is working on a reply...