Travelling the World



We have the Umbraco CMS (version 3) configured to use TinyMCE for WYSIWYG editing. It works quite well up until we want to insert some HTML content that TinyMCE strips out (like an embedded youtube video, or a screencast)

Here’s how to create a very simple Umbraco macro (using a c# user control) to allow you to insert arbitrary HTML code that won’t interfere with TinyMCE:

Create a visual studio solution and create InsertHTML.ascx with the following code:

< %@ Control Language="C#" AutoEventWireup="true" Codebehind="InsertHTML.ascx.cs"
    Inherits="YourNameSpace.InsertHTML" %>
< %=HTMLCode%>

The code-behind InsertHTML.ascx.cs just needs to have:

using System;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
 
namespace YourNameSpace
{
    public partial class InsertHTML : System.Web.UI.UserControl
    {
        private string __HTMLCode = "";
 
        public string HTMLCode
        {
            get
            {
                return __HTMLCode;
            }
            set
            {
                __HTMLCode = value;
            }
        }
 
    }
}

Build your DLL, drop it into the umbraco bin folder, and put the .ascx file in the \usercontrols\ directory. You’re almost done. Go to Developer -> Macros and create a new macro called “Insert HTML.” Point it to the user control on the server and be sure to check “use in editor.” Lastly, on the “Parameters” tab add a textMultiLine parameter and call it HTMLCode.

You should now see the “Insert HTML” macro as one of the options when you click the macro button in the TinyMCE editor. And we’re done.

Here’s a solution file extracted from my project:
Download Solution


5 Responses to “Insert Arbitrary HTML into Umbraco Pages”  

  1. 1 Wade

    Thanks, Tryed it but it justs says on the page?
    Im running v4

  2. 2 boris

    Hi Wade, unfortunately I don’t yet have umbraco 4 running (this was tested with umbraco 3).

  3. 3 Wade

    Boris are you able to send me the solution. Just in case i have done some thing wrong whilst creating it :) thanks

  4. 4 boris

    Hi Wade, I updated the post with a link to the solution file.

  5. 5 Berni_Ball

    Just wanted to say thank you!

    This worked a dream AND I really appreciate you spending your valuable time helping newbs like me.

Leave a Reply