1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Multiple Content blocks

Multiple Content blocks

2 posts, 0 answered
  1. Sravan Kumar
    Sravan Kumar avatar
    6 posts
    Registered:
    26 Aug 2011
    21 Nov 2011
    Link to this post
    Hi Telerik Sitefinity,

    This is Sravan from India,

    My question looks to be strange and funny, But what to do do requirement is like that,

    we have been developing a website using sitefinity 4.1, and we are almost at the end of project,

    Mean while My client reviewed the process, and express that If you can provide some content blocks apart from the default one with specific style sheet tagged with that, that will make my job more easy,  So that i can drop the control wherver i need and i want in later stages, so that total webpage can be controlled from admin end,

    So here is my question, Is it possible to develop a control with content block that we can place them in a ny placeholder and after that they can enter content and assign stylesheet according to that, and it will render content html encoded in the front end as the general editor is doing ,

    Note*  The default content block should be there itself,

    Like that i want to create multiple user defined content blocks,

    Its a bit very importent, can anybody have idea please suggest me,

    Thankyou, it would be more helpful for me if anybody have idea/solution

    awaiting reply

    regards

    Sravan
  2. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    16 Aug 2017
    24 Nov 2011
    Link to this post
    Hi Sravan Kumar,

    Can you please clarify what you mean by "with specific style sheet tagged with that [content block]", so we can give you a more specific advice?
    Are the styles from this stylesheet going to be applied to the text in the content block? If so, the easiest way to achieve this would be to modify the Content editor's ToolsFiles and add a reference to an external CSS file that contains your styles. Then you can substitute the default ToolsFile we're using with your custom one, and this will ensure that the ApplyCSS dropdown is populated with your custom CSS. You can check this forum thread which contains a detailed discussion on achieving similar functionality, and check out the videos and code samples we've provided there.
    If the functionality you require differs from the one described above, and your use case scenario is such that you need to have different content block widgets, let me elaborate a little bit on what's necessary to be done.
    The base class ContentBlock implements a ControlDesigner interface of type ContentBlockDesigner. In that designer you have the a control of type HtmlField, which is the content editor control itself. The HtmlField uses RadEditor which allows us to set different ToolsFiles for each instance of the control. We've gone a step further in extending this functionality, by allowing the HtmlField to load custom EditorToolsConfigurations that can be created through Administration->Settings->Advanced->Appearance and are retrieved from the AppearanceConfig.config configuration file.
    In order to achieve the desired functionality, you can create several different EditorToolsConfigurations, and in your ToolsFiles define the specific CSS that will be included in the ParagraphStyles and ApplyCSS dropdowns by default. For more information on how to customize the ParagraphStyles please take a look at this article from our RadEditor documentation, and for ApplyCSS - this one.
     You'll also need the default ToolsFile which we're using, I'm attaching it to the current response.
    Once you have your custom ToolsFiles for each ContentBlock added as custom configurations in the AppearanceConfig, you can then create a new custom control by inheriting from the ContentBlock class, like this:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Telerik.Sitefinity.Modules.GenericContent.Web.UI;
    using Telerik.Sitefinity.Web.UI.ControlDesign;
      
    namespace SitefinityWebApp.Controls
    {
        [ControlDesigner(typeof(ContentBlockDesignerA))]
        public class ContentBlockA:ContentBlock
        {
        }
    }
    Please note that instead of the default designer, your newly created ContentBlockA, uses a customized designer, where we'll be loading the different ToolsConfiguration for each ContentBlock:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Telerik.Sitefinity.Modules.GenericContent.Web.UI;
    using System.Web.UI;
      
    namespace SitefinityWebApp.Controls
    {
        public class ContentBlockDesignerA : ContentBlockDesigner
        {
            protected override void InitializeControls(Telerik.Sitefinity.Web.UI.GenericContainer container)
            {
                this.HtmlEditor.EditorToolsConfiguration = Telerik.Sitefinity.Web.UI.Fields.Enums.EditorToolsConfiguration.Custom;
                this.HtmlEditor.EditorToolsConfigurationKey = "ContentBlockA";
                base.InitializeControls(container);
            }
      
            protected override string ScriptDescriptorTypeName
            {
                get
                {
                    return typeof(ContentBlockDesigner).FullName;
                }
            }
        }
    }
    Please be careful to specify the correct EditorToolsConfigurationKey  which matches the corresponding ToolsFile with customized ParagraphStyles. in each ContentBlockDesidgerX.

    Once you're done, you can register the new custom controls in the Sitefinity PageControls toolbox and use them on any page inside Sitefinity - each ContentBlockX will be using its own EditorToolsConfiguration and load the corresponding ToolsFile with customized ParagraphStyles by default.

    I'm attaching a sample I've created for you, using the example given on the Paragraph Styles documentation article - it contains the default ToolsFile.xml with the custom ParagaphStyles defined at the bottom, a customized ContentBlockDesigner, ContentBlock, and the sample AppearanceConfig.config (this is for reference purposes only, the file is automatically generated when adding new EditorToolsConfigurations through Administration->Settings->Advanced->Appearance). 
    Please note that the above scenario does not limit to specifying a custom EditorToolsConfiguration only, you can easily manipulate any of the HtmlField's properties that are exposed in the designer class in case you want to perform some further customizations. If there's anything else we can help you with, please let us know.

    Regards,
    Boyan Barnev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
2 posts, 0 answered