How to customize the Content Editor
Hi,
I want to add a new toolbar button to the Content Editor (HtmlField) control in Sitefinity that will appear globally accross the whole site when the editor is shown. This new button will let the user to embed some video contents along with the other content entry. Can someone please tell me how to achieve this?
Thanks,
Duneel
Hello Duneel,
Thank you for contacting Telerik Support.
Follow the below steps to add the button to your Content Block Editor globally.
Open your project in Visual Studio
1. Create a file EditorTools.ascx in the root directory of your SitefinityWebApp project and paste the below sample code inside:
<%@ Control Language="C#" %>
<%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI" TagPrefix="sf" %>
<%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI.Fields" TagPrefix="sf" %>
<
sf:ResourceLinks
id
=
"resourcesLinks"
runat
=
"server"
>
<
sf:ResourceFile
Name
=
"CSS/myCSS.css"
/>
</
sf:ResourceLinks
>
<
sf:FormManager
ID
=
"formManager"
runat
=
"server"
/>
<
div
style
=
"width: 660px; overflow: hidden;"
>
<
sf:HtmlField
ID
=
"htmlEditor"
runat
=
"server"
Width
=
"99%"
Height
=
"370px"
EditorContentFilters
=
"DefaultFilters"
EditorStripFormattingOptions
=
"MSWord,Css,Font,Span,ConvertWordLists"
DisplayMode
=
"Write"
FixCursorIssue
=
"True"
EditorToolsConfiguration
=
"Custom"
EditorToolsConfigurationKey
=
"tools"
> <%--This key has to be the same as the key you add in AppearanceConfig.config--%>
</
sf:HtmlField
>
</
div
>
<
script
type
=
"text/javascript"
>
$("body").addClass("sfContentBlockDesigner");
</
script
>
<
root
>
<
tools
name
=
"MainToolbar"
enabled
=
"true"
>
<!--you'll be working with the buttons in the main section-->
<
tool
name
=
"AjaxSpellCheck"
/>
<
tool
name
=
"InsertSymbol"
/>
<
tool
name
=
"FormatCodeBlock"
/>
<
tool
separator
=
"true"
/>
<!--you can use tool separators to separate your button-->
<
tool
name
=
"EmbedVideo"
/>
<!--this will be your button-->
<
tool
separator
=
"true"
/>
</
tools
>
</
root
>
Hi Boyan,
Your solution worked like a charm. Thanks!!
Since now the tool buttons are defined in the xml file I'm not getting the same set of buttons as the content editor has by default. I need to have the default button set plus the new button to appear as in the attached screenshot. How do I do that?
Thanks,
Duneel
Hello Duneel,
Thank you for getting back to me.
I'm attaching a Tools.xml file containing all the buttons that Editor contains, including your custom button. Please review it and modify it according to your requirements.
I hope this information helps. I will be glad to assist you further.
Kind regards,
Boyan Barnev
the Telerik team
Thank you so much Boyan! The xml file did the trick. You guys are great!!
Hi Boyan, Im trying to add a custom toolbar button as well. I was able to create the files and set up EditorConfigurations and ViewMap but Im getting the following error when trying to edit a content block:
A required control was not found in the template for "~/EditorTools.ascx". The control must be assignable from the type "Telerik.Sitefinity.Web.UI.ControlDesign.ContentSelector" and must have ID "sharedContentSelector".
EditorTools.ascx code is taken straight from your example.
Any idea would be greatly appreciated!
Hi Jack,
Please try with the bellow template for the HtmlField:
<%@ Control Language="C#" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI" TagPrefix="sf" %>
<%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI.Extenders" TagPrefix="sf" %>
<
sf:ConditionalTemplateContainer
ID
=
"conditionalTemplate"
runat
=
"server"
>
<
Templates
>
<
sf:ConditionalTemplate
Left
=
"DisplayMode"
Operator
=
"Equal"
Right
=
"Read"
runat
=
"server"
>
<
sf:SitefinityLabel
id
=
"titleLabel_read"
runat
=
"server"
WrapperTagName
=
"div"
HideIfNoText
=
"false"
CssClass
=
"sfTxtLbl"
/>
<
sf:SitefinityLabel
id
=
"viewControl"
runat
=
"server"
WrapperTagName
=
"div"
HideIfNoText
=
"false"
CssClass
=
"sfRTFContent"
/>
</
sf:ConditionalTemplate
>
<
sf:ConditionalTemplate
Left
=
"DisplayMode"
Operator
=
"Equal"
Right
=
"Write"
runat
=
"server"
>
<
sf:ResourceLinks
id
=
"resourcesLinks2"
runat
=
"server"
>
<
sf:EmbeddedResourcePropertySetter
Name
=
"Telerik.Sitefinity.Resources.Themes.Default.Styles.EditorDialogs.css"
Static
=
"true"
ControlID
=
"editControl"
ControlPropertyName
=
"DialogsCssFile"
/>
<
sf:ResourceFile
Name
=
"Telerik.Sitefinity.Resources.Themes.Default.Styles.Window.css"
Static
=
"true"
/>
</
sf:ResourceLinks
>
<
asp:Label
ID
=
"titleLabel_write"
runat
=
"server"
CssClass
=
"sfTxtLbl"
AssociatedControlID
=
"editControl"
/>
<
asp:LinkButton
ID
=
"expandLink"
runat
=
"server"
OnClientClick
=
"return false;"
CssClass
=
"sfOptionalExpander"
/>
<
asp:Panel
ID
=
"expandableTarget"
runat
=
"server"
CssClass
=
"sfEditorWrp sfClearfix"
>
<
telerik:RadEditor
ID
=
"editControl"
runat
=
"server"
Skin
=
"Sitefinity"
Width
=
"100%"
Height
=
"550px"
EnableResize
=
"False"
EditModes
=
"Design,HTML"
DialogHandlerUrl
=
"~/Telerik.Web.UI.DialogHandler.axd"
Content
=
""
NewLineBr
=
"False"
StripFormattingOptions
=
"Css,Font,Span"
>
<
FlashManager
ViewPaths
=
"~/Files"
UploadPaths
=
"~/Files"
DeletePaths
=
"~/Files"
/>
</
telerik:RadEditor
>
<
sf:RadEditorCustomDialogsExtender
runat
=
"server"
id
=
"editorCustomDialogsExtender"
TargetControlID
=
"editControl"
/>
<
sf:SitefinityLabel
id
=
"descriptionLabel"
runat
=
"server"
WrapperTagName
=
"div"
HideIfNoText
=
"true"
CssClass
=
"sfDescription"
/>
<
sf:SitefinityLabel
id
=
"exampleLabel"
runat
=
"server"
WrapperTagName
=
"div"
HideIfNoText
=
"true"
CssClass
=
"sfExample"
/>
</
asp:Panel
>
</
sf:ConditionalTemplate
>
</
Templates
>
</
sf:ConditionalTemplateContainer
>
Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>
Hi Radoslav,
I tried your code and got this error:
Hello Devin,
Can you please let me know for which class you have mapped this template. It seems that you have mapped the template for HTML field control for a class (control or designer) that utilizes HTML field control.
All the best,
Radoslav Georgiev
the Telerik team
Hi Radoslav,
I was attempting to add the Apply CSS Class dropdown. I found a simpler solution here www.sitefinity.com/.../customizing_the_sitefinity_wysiwyg_editor.aspx.
Thanks!
Devin
I am having the same Issue. I want to adjust the height of the HtmlField Editor. I am unable to do and try to put the template as you suggested in this post. Please, reply me with recommended adjustment I need to do in this issue.
Hi Ahmed,
Please download the latest Sitefinity SDK. It contains all of the default built in templates for Sitefinity controls. You can take the template for the HTML field from there.
Kind regards,
Radoslav Georgiev
the Telerik team