5

I need to prevent Sitecore from removing my script tags in RTE for specific templates even when HtmlEditor.RemoveScripts is true.

I have looked at https://laubplusco.net/customizing-sitecore-rich-text-field-configuration/ https://jermdavis.wordpress.com/2014/04/06/ever-wished-the-rich-text-field-didnt-mess-with-your-html/

but both didn't work, I'm not sure if this is related to the articles being old or I'm doing something wrong.

Setting HtmlEditor.RemoveScripts value to false works, but when I use the below when the setting value is true it doesn't:

base.SetupFilters();
base.Editor.DisableFilter(EditorFilters.RemoveScripts);

using Sitecore 8.2 u 7

  • 4
    Instead of programatically trying to enable/disable this setting, I would add a Multi-line Text field to those templates to allow you to add script tags to (my first choice would be to handle this differently and avoid specifying JS files like this at all) – jammykam Sep 23 '18 at 18:23
  • Thanks. I actually agree with you and we have already used Multi-line Text to supply js sources. But the customer is pushing to allow js in RTE!! – TamerM Sep 26 '18 at 9:47
2

First of all, the above links (in the question) do not work anymore. Any inline js is removed on several levels and so it's extremely difficult to handle all of them without making your upgrade process a nightmare!

However I managed to find a workaround, by reversing the logic:

  1. Set the HtmlEditor.RemoveScripts value to false. So js is never removed
  2. Use one of the links above (in the question) to override Sitecore.Shell.Controls.RichTextEditor.EditorConfiguration and add your logic to always enable the RemoveScripts filter (which removes inline js) except for certain templates to keep the filter disabled.

This workaround has the downside of having the HtmlEditor.RemoveScripts setting value as false, however Sitecore would function as if it was true.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.