Try our conversational search powered by Generative AI!

Cannot get children or descendents correctly

Vote:
 

My client has a structrure that looks like below.

The "Norge" has one language NO (norwegian), the first child "Produkter" (products) have a master language EN and a NO version.

The master EN on "Produkter" is expired.

The NO version on "Produkter" is published and can be accessed through menues without beeing logged in etc.

I cannot get the first child "Produkter" trough any means of code. I have tried many ways of doing this.

_contentRepository.GetChildren<PageData>(XX.ContentLink, languageSelector.Language);

_contentRepository.GetDescendents(XX.ContentLink).Where(x => x.Language.Name == languageSelector.Language.Name).

public static IEnumerable<PageData> GetDescendants(PageReference pageLink)
        {
            foreach (var page in DataFactory.Instance.GetChildren(pageLink))
            {
                yield return page;
                foreach (var child in GetDescendants(page.PageLink))
                {
                    yield return child;
                }
            }
        }

I have checked acccessrights.

If I skip the "FilterForDisplay" extension I can get the last child "Produkter" which someone is editing.

Anyone have an idea why this is? It's almost like the first child "Produkter" is not really under the "Norway" parent.

Worth mentioning that this is a custom controller with a custom route in global.asax.

#247946
Edited, Feb 01, 2021 10:28
Vote:
 

Perhaps IContentLoader.GetChildren<T>(ContentReference contentLink, CultureInfo.GetCultureInfo("no")) would work in your case. 

#247950
Feb 01, 2021 11:02
Carl S - Feb 01, 2021 11:23
Nope. Same issue. Like I wrote, I get some pages but not all pages.
Vote:
 

Ok. Update. After much testing I know seem to get all children (decendents). English version:

Norwegian version

But when I use this extension I only get the EN version of the page. Why? And how do I get the NO version link?

public  static string GetExternalUrl(this ContentReference contentLink)
        {
            if (contentLink.IsNullOrEmpty()) return null;

            var urlResolver = ServiceLocator.Current.GetInstance<IUrlResolver>();

            var internalUrl = urlResolver.GetUrl(contentLink);
            if (string.IsNullOrEmpty(internalUrl)) return null;

            var url = new UrlBuilder(internalUrl);
            EPiServer.Global.UrlRewriteProvider.ConvertToExternal(url, null, Encoding.UTF8);
            return UriSupport.AbsoluteUrlBySettings(url.ToString());
        }

As you can see I do have the correct language version. But the link still is EN version.

The LinkURL "/link/3edeeac25cd246c9919edfe403c6f020.aspx" also points to EN version

#248062
Edited, Feb 03, 2021 6:20
Vote:
 

Ok extremely ugly solution, but it works. Does anyone have any other nicer solution?

        private string BuildUrlSegments(PageData page, CultureInfo culture, StringBuilder sb)
        {
            if (page is null || page is CountryStartPage) return sb.ToString();
            sb.Insert(0, page.URLSegment + "/");
            var parent = _contentLoader.Get<PageData>(page.ParentLink, culture);
            return BuildUrlSegments(parent, culture, sb);
        }
#248064
Feb 03, 2021 6:54
Vote:
 

You can use the overload which takes a language parameter 

string GetUrl(ContentReference contentLink, string language, UrlResolverArguments urlResolverArguments);

#248077
Feb 03, 2021 13:34
Vote:
 

Thanks. This works

#248137
Feb 04, 2021 8:44
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.