Save urls as friendly urls in tinymce editor

Vote:
 

Is there an easy way of changing the behavior of the edit/insert link plugin in tinymce so that if I pick an episerver page or a media it saves it as a friendly url instead of like /link/cb750554e595497cbee028391fb2e291.aspx?id=17672 or do I need to build a new plugin from scratch?

#150668
Jun 27, 2016 13:24
Vote:
 

If you render your XHTML property using @Html.PropertyFor(....) any links will be parsed by Episerver. If you are working with the property html directly, you need to this your self by creating a helper method that parses the html and replaces the guid based links with friendly urls. 

#150670
Jun 27, 2016 13:41
Vote:
 

The internal url is a good idea to keep since otherwise you will create a lot of 404s if you change urlsegment or move a page/media in the structure. So you probably want to keep it and resolve the friendly url later in the chain instead...

#150671
Jun 27, 2016 14:46
Vote:
 

With this specific xhtml editor i need to save it to a seperate database for use in a tool i'm working with so @Html.PropertyFor won't work in this case sadly and this tool won't be able to translate the internal url to the friendly ur.

#150672
Jun 27, 2016 15:08
Vote:
 

I would then convert it before saving it. Something like:

        public static XhtmlString ToExternalLinks(this XhtmlString xhtmlString)
        {
            var result = new StringBuilder();
            foreach (var fragment in xhtmlString.Fragments)
            {
                var urlFragment = fragment as UrlFragment;
                result.Append(urlFragment != null ? UrlResolver.Current.GetUrl(new UrlBuilder(urlFragment.InternalFormat), ContextMode.Default) : fragment.InternalFormat);
            }
 
            return new XhtmlString(result.ToString());
        }
#150674
Jun 27, 2016 15:18
Vote:
 

Then I guess you need parse the html before saving it in the database (you can use Regex to find links in the html).

#150675
Jun 27, 2016 15:19
Vote:
 

Thanks Daniel Ovaska! worked great!

#150678
Jun 27, 2016 15:50
Vote:
 

Sweet!

#150679
Jun 27, 2016 15:51
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.