I think your question duplicates Rewritten action links in rich text area
Do you access the XHtmlString directly?
Try something like this:
var html = Html.XhtmlString(Model).ToString();
PS: There was a bug with Html.XhtmlString that was fixed in 7.15, so If you use an older version you might have problems with blocks inside XHtmlString. Ref: http://world.episerver.com/support/Bug-list/bug/117117
I'm currently on 7.13
And I forgot to mention a crucial detail.
If I use @Html.DisplayFor(m => m.CurrentPage.MainBody) it works fine.
But I'm displaying the XhtmlString through a "filter" helper that inserts a id attribute for every <h2> and also prepends a <ul> with a index list of links to each <h2 id="xxx">.
My method looks like this now and it works.
public static IHtmlString RenderPageIndex(this HtmlHelper htmlHelper, XhtmlString markup) { var result = htmlHelper.XhtmlString(markup).ToString(); //var result = markup.ToString(); // <-- Old non working code result = htmlHelper.AddIdsToH2(result); result = htmlHelper.BuildIndexList(result); return new MvcHtmlString(result); }
Thanks @Tore!
You should upgrade to 7.15 (or newer) to get blocks working correctly. Ref: http://world.episerver.com/support/Bug-list/bug/117117
I have same issue in Episerver 10
hyperlinks which refering to any cms page displays as /link/some_weird_guid.aspx instead of the actual link
I able to convert the url if it is located in contentreference but I don't know how can I fix the issue inside the wysiwyg editor
Hi,
Instead of calling xhtmlString.ToString() you can call xhtmlString.ToHtmlString().
That's the exact thing I did but still the hyperlink inside the htmlstring created as guid and..
When you say created, do you mean rendered or stored in database? Because links should be stored like that.
Does the page you're linking to still exist?
Can you post your code?
Thanks Johan
what is happened is I've just put a text on wysiwyg editor and create a hyperlink to one of the existing page
when getting the wysiwyg content as HTML , the link which inside the href tag stored as the weird formatted(guid.aspx) instead of actual link address
Snippet
Blurb = currentBlock.Description?.ToHtmlString(),
As mentioned above you need to do it through the HtmlHelper.XhtmlString(xhtmlString). Otherwise the links will not be converted and blocks will not be displayed. If you don't have access to a HtmlHelper you can do something like this: http://antecknat.se/blog/2016/03/07/xhtmlstring-render-blocks-and-convert-link-to-external-without-htmlhelper/
Thanks a lot
really helpful
is there any way to filter the fragment
I've found
GetFilteredFragments
but did not find any document for using that
So I don't want url's like these "/link/some_weird_guid.aspx?id=XX" when I create a link using TinyMCE
but instead would like something more friendly like "/about-us/our-mission/"
I'm using the UrlResolver to achive this elsewhere in my views but how can I fix url's that are embeded inside a XHTMLString?
Can I add a DisplayTemplate to handle this somehow (LinkItem.cshtml)?