Friendly url's for links created in TinyMCE

Vote:
 

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)?

#115294
Jan 13, 2015 12:27
Vote:
 

I think your question duplicates Rewritten action links in rich text area

#115297
Jan 13, 2015 12:39
Vote:
 

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

#115304
Edited, Jan 13, 2015 15:12
Vote:
 

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!

#115306
Jan 13, 2015 15:32
Vote:
 

You should upgrade to 7.15 (or newer) to get blocks working correctly. Ref: http://world.episerver.com/support/Bug-list/bug/117117

#115308
Edited, Jan 13, 2015 15:39
Vote:
 

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

#175733
Mar 01, 2017 4:44
Vote:
 

Hi,

Instead of calling xhtmlString.ToString() you can call xhtmlString.ToHtmlString().

#175734
Mar 01, 2017 6:50
Vote:
 

That's the exact thing I did but still the hyperlink inside the htmlstring created as guid and..

#175735
Mar 01, 2017 6:54
Vote:
 

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?

#175736
Mar 01, 2017 7:00
Vote:
 

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(),
#175737
Mar 01, 2017 7:05
Vote:
 

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/

#175754
Mar 01, 2017 10:42
Vote:
 

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
#175789
Mar 02, 2017 7:11
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.