Content Block Template
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.
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
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.
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
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?
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
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?
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
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;
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
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);
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
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);
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
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