More in this section

Forums / Developing with Sitefinity / Adding scripts to Content Blocks

Adding scripts to Content Blocks

2 posts, 0 answered
  1. Ed
    Ed avatar
    4 posts
    19 Jul 2012
    31 Jan 2013
    Link to this post

    Hello, I am trying to add script tags to content blocks. By default RadEditor strips out script tags. I was able to disable this for shared/generic content blocks, but not the content blocks at the Page level. Does anybody know how to do this at the page level?

    I was able to do this for shared/generic content blocks by going to:

    Settings > Advanced > Content > Controls > ContentBackend > Views > ContentBacked[Edit/Insert] > Sections > MainSection > Fields > Content

    Then set "Rad Editor's content filters" to:

    FixUlBoldItalic, FixEnclosingP, IECleanAnchors, MozEmStrong, ConvertFontToSpan, ConvertToXhtml, IndentHTMLContent, EncodeScripts, OptimizeSpans, ConvertCharactersToEntities, PdfExportFilter, ConvertInlineStylesToAttributes

    Note: this should be the defaults minus "RemoveScripts"

    Again, this works for shared/generic content blocks, but not with Page content blocks.



  2. Jochem Bökkers
    Jochem Bökkers avatar
    787 posts
    13 Aug 2007
    01 Feb 2013 in reply to Ed
    Link to this post

    Hey Ed,

    At page-level you're running into an old issue where the filters aren't applied. That bug existed up to v5.2, so more than likely they fixed it implementing the new shared content functionality but haven't gotten around to implement it on a page/template level.

     You can save script tags, just don't try and edit them, or they'll get stripped out.

    Before you could map the template of HtmlField by doing the following:

    Create .ascx file in your poject and paste the template of Sitefinity html
    field. (attach code behind to the template to configure content filters in it)

    <%@ 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">
            <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 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" />
                <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">
                        StripFormattingOptions="Css,Font,Span" >
                        <FlashManager ViewPaths="~/Files" UploadPaths="~/Files" DeletePaths="~/Files" />
                    <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" />

    2. Map the template from
    Administration->Settings->Advanced->Controls->ViewMap crete new

    Host: Telerik.Sitefinity.Web.UI.Fields.HtmlField

    Layout: Relative path to to the template created in step 1 ~/HtmlField.ascx

    Restart the application and the template will be in use

    For the editor disable content filters on the Prerender event

    protected void Page_Load(object sender, EventArgs e)
               editControl.PreRender += new EventHandler(editControl_PreRender);
           void editControl_PreRender(object sender, EventArgs e)

2 posts, 0 answered