Insert Arbitrary HTML into Umbraco Pages
5 Comments Published by boris February 18th, 2009 in ballroom, google analytics, technology, umbracoWe 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