Try our conversational search powered by Generative AI!

Save urls as friendly urls in tinymce editor


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?

Jun 27, 2016 13:24

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. 

Jun 27, 2016 13:41

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...

Jun 27, 2016 14:46

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.

Jun 27, 2016 15:08

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());
Jun 27, 2016 15:18

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

Jun 27, 2016 15:19

Thanks Daniel Ovaska! worked great!

Jun 27, 2016 15:50


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.