Episerver, like the majority of CMS solutions on the market, uses the TinyMCE WYSIWYG editor to provide content editors the ability to add and edit content within the CMS. By default, Episerver locks TinyMCE down to only allow basic text editing. In a lot of companies this is OK, but, if you need to use iFrames, SVGs or even inline Javascript then you'll probably notice very quickly that when you try to save your page, Episerver strips out certain attributes from your HTML elements. There is a fix to this... you need to tell Episerver which extra attributes that you want to allow. In today's post I'm going to explain how to configure Episerver to allow any attribute that you want on an iFrame.

Configuring TinyMCE in Code

In order to configure TinyMCE you will need to use the Episerver [TinyMCEPluginNonVisualAttribute] attribute, like so:

The code above will allow any attribute to be added to an iFrame within the content editor. I'll briefly discuss what each line is doing:

  • PlugInName & class name: Can be anything you want
  • AlwaysEnabled: Should be obvious
  • ServerSideOnly: Not enabling this will result in a javascript error. Episerver will attempt to find a physical gile called CustomValidElement. tiny_mce_serversideonly
  • EditorInitConfigurationOptions: Your rules. IN my example I'm being lazy and allowing everything. If you want to be really anal and lock everything down, then I suggest using this rule instead:
  • Configuring TinyMCE in Config

    After you have created the TinyMCE configuration, you need to tell Episerver to use it. If you want more information about this step, I suggest reading the Epi guide on TinyMCE here. Add this line into your web.config (or episerver.config for legacy projects):

One thing to note is that Episerver will always strip out the 'name' attribute, regardless if you add it as a rule, try it yourself if you don't believe me:

No matter what I've tried I can't prevent the 'name' attribute from being stripped out. You can use the 'id' so there is a workaround.