November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
Hi, William,
I use PageReference.ParseUrl instead of PermanentLinkUtility.GetContentReference(), try out the following code:
public static List<PageData> ToPages(this LinkItemCollection linkItemCollection) { var pages = new List<PageData>(); if (linkItemCollection != null) { foreach (var linkItem in linkItemCollection) { string linkUrl; if (!PermanentLinkMapStore.TryToMapped(linkItem.Href, out linkUrl)) continue; if (String.IsNullOrEmpty(linkUrl)) continue; var pageReference = PageReference.ParseUrl(linkUrl); if (PageReference.IsNullOrEmpty(pageReference)) continue; var page = DataFactory.Instance.GetPage(pageReference, LanguageSelector.AutoDetect()); if (page != null) { pages.Add(page); } } } return pages; }
Let me know if this doesn't work.
Hi Marija,
Thanks for your suggestion, unfortunately I still get the same error. Which version of EPi are you using that snippet for?
It's 7.19, which one are you using?
I'll give it another check on latest...
Give this a try:
public static List<PageData> ToPages(this LinkItemCollection linkItemCollection) { var pages = new List<PageData>(); if (linkItemCollection != null) { foreach (var linkItem in linkItemCollection) { if (String.IsNullOrEmpty(linkItem.Href)) continue; string linkUrl; if (PermanentLinkMapStore.TryToMapped(linkItem.Href, out linkUrl)) { var urlBuilder = new UrlBuilder(linkUrl); var urlResolver = ServiceLocator.Current.GetInstance<UrlResolver>(); var page = urlResolver.Route(urlBuilder) as PageData; if (page != null) { pages.Add(page); } } } } return pages; }
For me it works, tested on latest version. Make sure to test it in edit mode as well. // UPDATE: works well for me in edit mode as well, briefly tested it...
Might be good not to call var urlResolver = ServiceLocator.Current.GetInstance<UrlResolver>(); in foreach :)
That did the trick, thanks! :)
Yes, I will inject it instead, used ServiceLocator in my example merely as a convenience.
I have a block type that has a LinkItemCollection property, with which I want to render a slider. Each slider item should render header, image and body text from the pages that the link items point to.
In order to do that I have to convert the link items to pages, so I tried the snippet from Joel Abrahamsson (http://joelabrahamsson.com/convert-a-linkitemcollection-to-a-list-of-pagedata/), but I always get an empty page/content reference. The same error occurs when I use PermanentLinkUtility instead:
The links all have the format "/link/81242f7222424dc488f30bcdb9734c30.aspx", don't know if that has anything to do with the error?