Friendly url's for links created in TinyMCE

Member since: 2014

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
  • Member since: 2006

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

    #115297 Jan 13, 2015 12:39
  • 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
  • Member since: 2014

    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
  • 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
  • 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
  • Member since: 2007

    Hi,

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

    #175734 Mar 01, 2017 6:50
  • That's the exact thing I did but still the hyperlink inside the htmlstring created as guid and..

    #175735 Mar 01, 2017 6:54
  • Member since: 2007

    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
  • 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
  • Member since: 2004

    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
First   1 2   Last