Contents
During the installation process CKEditor will be automatically enabled on Publishing Sites. However, if you have modified the default master pages or if you are using your own custom master pages, you will need to manually enable CKEditor on these sites.
Adding CKEditor to a Master Page
The master pages are located in the following folders:
-
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\GLOBAL\default.master
-
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\FEATURES\PublishingLayouts\MasterPages\
For each master file that is used on your sites you need to introduce the changes described below.
Step 1: Register an Assembly
To enable CKEditor, add the following code in the Register
section at the top of the page:
<%-- Start CKEditorForSharePoint --%> <%@ Register TagPrefix="my" Assembly="CKEditorForSharePoint, Version=1.0.0.0, Culture=neutral, PublicKeyToken=2c0483256f3286a8" Namespace="CKEditorForSharePoint" %> <%-- End CKEditorForSharePoint --%>
Step 2: Add the Page_Load Method
Add the following code straight below the Register
tag or somewhere inside the <body>
of the master page:
<%-- Start CKEditorForSharePoint --%> <script language="C#" runat="server"> private void Page_Load(object sender, EventArgs e) { this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "CKEditorConfigScript", string.Format("var CKTabConfig =\"{0}\";", SPUtils.ReadConfigurationForCKEditor()), true); } </script> <%-- End CKEditorForSharePoint --%>
<%-- Start CKEditorForSharePoint --%>
and <%-- End CKEditorForSharePoint --%>
are not required, but they will be helpful e.g. during the uninstallation process or when modifying the page to understand what they are used for.
Step 3: Enable Code Blocks in Master Pages
In the previous step we added some server-side code to the page. In order to execute this part of code, SharePoint must be configured to allow this operation. If code blocks are disallowed, you will see the following error:
Parser Error Message : Code blocks are not allowed in this file
Code blocks can be enabled in the configuration/SharePoint/PageParserPaths
configuration section of the web.config
file. Find the <PageParserPaths>
option and add an <PageParserPath>
element there:
<PageParserPaths> <PageParserPath VirtualPath="/_catalogs/masterpage/*" CompilationMode="Always" AllowServerSideScript="true" IncludeSubFolders="true"/> </PageParserPaths>
VirtualPath
can insert code that will be executed on the server side with no restrictions. A good location to specify as a PageParserPath
is the location where you store your masterpages, for example /_catalogs/masterpage
.