We have a strange problem regarding links added inside the editor. Once the page is viewed direclty the links works fine. Like "subcat/subcat/page..." but, when that page is added to a pageReference and we pick up the XhtmlString from the pageReference, the link is something like this "link/ac594486fa2b455f8ac991523b92d3c8.aspx".
The difference I can find is that parserMode for the XhtmlString is set to "RemapLinks" instead of "LeaveMappedLinks". This property is also set to readOnly on the propery.
There is not so much to show in code, but we are using DataFactory to get the XhtmlString we are using on StartPage in this example:
IEnumerable testPages = DataFactory.Instance.GetDescendents(PageReference.StartPage);
TestPage testPage = testPages.Where(x => x.ContentLink.ID == startPage.TestLink.ID).FirstOrDefault();
My question is why this happens?What is the best way to solve the issue?
We are using Episerver version 7.5.
Hmm not sure what you are asking?
Links in xhtml fields are stored as internal links with guids (link/ac594486fa2b455f8ac991523b92d3c8.aspx). When the string is then rendered, the links are transformed to friendly urls (subcat/subcat/page...). This is to make it possible to move stuff around in edit mode without ever breaking links.
If you just want the actual html that will be rendered to the end user you can use the method
If you are interested in finding a single link and do something with it use the Fragments collection on the xhtml string property and loop through that. Use UrlResolver to get the friendly url if needed.
No, this was not exaclty what i meant.
Case 1:Create a new XhtmlString property, add this to a normal view, the links (internal links) added from inside the editor works as expected (Example: "page1/subpage/my-page")
Case 2:Create another page with a PageReference property and from inside Episerver add the page created from "Case 1". Then print the XhtmlString property to that view. The output from the XhtmlString property is then (Example: "link/[guid].aspx" = and looks like this: "link/ac594486fa2b455f8ac991523b92d3c8.aspx".
I am talking about the complete output from the XhtmlString. It behaves different if it is added directly to the page (case 1) or if I reference the page and print it from there. The pages and properties is exactly the same.
The only difference I could find is the parserMode setting on the XhtmlString property that is different.
I want the links behave the same, as frindly urls to other pages in the solution.
How do you output it?
If you map it somewhere before outputting it, try using
viewmodel.xhtmlWithFriendlyUrls = referencedPage.MainBody.ToHtmlString(); //will trigger Episerver to convert all internal links to external including blocks etc...
and then in Razor just use .Raw to output...?
In the view you can also use @Html.DisplayFor(x => x.OtherPage.Mainbody) or PropertyFor. It sounds to me that you're having the issue Daniel is trying to explain.
Or how are you printing the xhtml property now?
Thank you for your reply.
I tried to map it to a variable before output but ToHtmlString() did not do anything more than just a string. Still wrong format of the links.
DisplayFor did kind of work, but not with the template output we are using.
In the view we is referenceing to a template @Template...outputMethod(viewModel, ...)
Inside the template.cshtml we print the property direclty as @Model.prop. I´m not sure it is possible to use DisplayFor directly in the template, that option is not avalible. Anyway, without the templete it works fine. Maybe I should just remove the template put it directly i the view.