More in this section

Forums / General Discussions / Content Block Template

Content Block Template

15 posts, 0 answered
  1. Shawn
    Shawn avatar
    79 posts
    Registered:
    01 Jun 2010
    22 Nov 2010
    Link to this post
    How do you edit the widget template used for the "Content Block" control?  I don't see it's template listed under "Widget Templates" and I don't want my html wrapped in a div with a class of sfContentBlock.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    22 Nov 2010
    Link to this post
    Hi Shawn,

    1. The control has a CssClass property where you could set the div class name and replace the default sfContentBlock.

    2. The only way to remove the div tag is overriding RenderBeginTag and RenderEndTag methods of the ContentBlock control which requires a custom control. The <div> is dynamically added in these methods.

    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Shawn
    Shawn avatar
    79 posts
    Registered:
    01 Jun 2010
    22 Nov 2010
    Link to this post
    I saw that I am able to set the css class, but there appears to be a bug in it.  I remove the value but it doesn't seem to save.  It's just gets replaced with the sfContentBlock.

    What's the reasoning behind adding the div?  Can I vote to add another property "wrapper element" to the Content Block control?  If it's null, Sitefinity doesn't wrap it in anything.
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    23 Nov 2010
    Link to this post
    Hi Shawn,

    CssClass property comes from WebControls class. If CssClass property is an empty string we set sfContentBlock. If you type a value to CssClass property it should be set by the control.

    The idea of the property is to set a css class that will style the text you entered in ContentBlock control.

    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Shawn
    Shawn avatar
    79 posts
    Registered:
    01 Jun 2010
    23 Nov 2010
    Link to this post
    I was asking the reasoning behind wrapping the Generic content block in a div.  I understand the use for the css class.  3.7 didn't wrap Generic content in a div, right?
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    23 Nov 2010
    Link to this post
    Hello Shawn,

    "The idea of the property is to set a css class that will style the text you entered in ContentBlock control."
    In 3.x we do not use CssClass property for GenericContent control.

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  7. Shawn
    Shawn avatar
    79 posts
    Registered:
    01 Jun 2010
    23 Nov 2010
    Link to this post
    Duly noted.  My apologies...I must have skipped right over that sentence.  How about adding a WrapperTagName property that defaults to div so you can specify if you would like it wrapped in a div?
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    23 Nov 2010
    Link to this post
    Hi Shawn,

    We would consider this option, but we will not be able to implement this for the official release.

    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  9. Shawn
    Shawn avatar
    79 posts
    Registered:
    01 Jun 2010
    23 Nov 2010
    Link to this post
    Looking at the code for the ContentBlock I noticed that there is an "if" statement wrapped around the CssClass.  If there isn't a CssClass provided then it isn't supposed to be wrapped in a div.  The problem is that the CssClass is being set to "sfContentBlock" if it's empty or null.  The default value should be "sfContentBlock" but if it gets set to "" then the content block should not be wrapped in a div.  This seems to be a bug not a feature request.

    public override void RenderBeginTag(HtmlTextWriter writer)
        {
            if (!string.IsNullOrEmpty(this.CssClass))
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Class, this.CssClass);
                writer.RenderBeginTag(HtmlTextWriterTag.Div);
            }
        }
     
        public override void RenderEndTag(HtmlTextWriter writer)
        {
            if (!string.IsNullOrEmpty(this.CssClass))
            {
                base.RenderEndTag(writer);
            }
        }

    public override string CssClass
        {
            get
            {
                if (string.IsNullOrEmpty(base.CssClass))
                {
                    return "sfContentBlock";
                }
                return base.CssClass;
            }
            set
            {
                base.CssClass = value;
            }
        }
  10. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    23 Nov 2010
    Link to this post
    Hello Shawn,

    Let's see this again.
    "If CssClass property is an empty string we set sfContentBlock. If you type a value to CssClass property it should be set by the control."

    sfContentBlock  is added, then a div is generated. sfContentBlock is a css class that is used by Basic and Default Theme to style the control. If  you put a dummy css class the control will be wrapped in a div again.

    The div is always generated no matter you type a value to the CssClass property or not.

    And again the only way to get around this issue in the RC is overriding renderbegintag and renderendtag methods.

    The solution here is exposing a new property where you can set whether you want to see noting, div, span or another element.

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  11. Shawn
    Shawn avatar
    79 posts
    Registered:
    01 Jun 2010
    23 Nov 2010
    Link to this post
    Ivan,

    I'm just trying to distinguish between a bug and a feature request.  I understand the workaround and have already implemented it.  I'm helping to identify a bug (if that's what this is).  The code below is taken from Telerik.Sitefinity.Modules.GenericContent.Web.UI.ContentBlock.  Why does the "if" statement exist when CssClass will never be null or empty?  This led me to believe the intention of the ContentBlock control is to wrap the content in a div ONLY when a CssClass is specified. 

    public override void RenderBeginTag(HtmlTextWriter writer)
       {
           if (!string.IsNullOrEmpty(this.CssClass))  //why have an if statement when CssClasss will never be empty or null
           {
               writer.AddAttribute(HtmlTextWriterAttribute.Class, this.CssClass);
               writer.RenderBeginTag(HtmlTextWriterTag.Div);
           }
       }
     
       public override void RenderEndTag(HtmlTextWriter writer)
       {
           if (!string.IsNullOrEmpty(this.CssClass)) 
           {
               base.RenderEndTag(writer);
           }
       }
  12. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    23 Nov 2010
    Link to this post
    Hi Shawn,

    If I create a custom control and override CssClass property and return an Empty.String and if there is no such a check in the render?

    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  13. Shawn
    Shawn avatar
    79 posts
    Registered:
    01 Jun 2010
    23 Nov 2010
    Link to this post
    Then you don't write the class attribute on the div..not ignore the div altogether.  I would expect the code to look like this:

    public override void RenderBeginTag(HtmlTextWriter writer)
        {
            if (!string.IsNullOrEmpty(this.CssClass))
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Class, this.CssClass);
            }
            writer.RenderBeginTag(HtmlTextWriterTag.Div);
        }

    public override void RenderEndTag(HtmlTextWriter writer)
       {
              base.RenderEndTag(writer);
       }


    Let me re-phrase my question.  Why does the Content Block control only wrap content in a div when the CssClass is present..as opposed to all the time like the code above? 

    I thought it was a bug...if it's not then we can consider this discussion closed.  It took a lot longer to make these posts than it did to create a new control and override the proper methods and plug it into Sitefinity. 
  14. Gunnar
    Gunnar avatar
    10 posts
    Registered:
    30 Sep 2008
    27 Dec 2016 in reply to Shawn
    Link to this post

    I am having the same issue with the sfContentBlock div. Have you by any means published the code for your new clean control implementation? I would love to reuse it for my project.

    rgds/Gunnar

  15. Victor Leontyev
    Victor Leontyev avatar
    65 posts
    Registered:
    01 Jul 2014
    28 Dec 2016 in reply to Gunnar
    Link to this post

    Hi Gunnar,

    You mean source code for "Content Block" widget?

    You can find "feather" implementation of Content block widget here: https://github.com/Sitefinity/feather-widgets/tree/master/Telerik.Sitefinity.Frontend.ContentBlock

15 posts, 0 answered