如何覆盖“富内容”区域中webparts周围呈现的表格?
我已成功删除了围绕webpartzones及其webparts的表格,但无法确定如何删除Rich Content区域webparts周围的表格。
我没有使用内容编辑器WebPart。
我正在使用的“Rich Content”区域是使用PublishingWebControls:RichHtmlField创建的。
这是包含内容和webparts的控件。
赏金here。
答案 0 :(得分:0)
我过去一直在考虑这个问题而且我提出了两个选项,虽然没有一个很吸引人,所以没有实现它们:
创建自定义富文本字段。覆盖渲染,使用TextWriter对象调用base.Render并将生成的html放在变量中,然后在写入输出之前“手动”清理它。
创建自定义富文本字段。覆盖渲染,但不是调用base.Render,而是自己处理插入webparts的魔力。 (这可能比较棘手。)
更新,我使用一些示例代码来最小化RichHtmlField的输出:
public class SlimRichHtmlField : RichHtmlField
{
protected override void Render(HtmlTextWriter output)
{
if (IsEdit() == false)
{
//This will remove the label which precedes the bodytext which identifies what
//element this is. This is also identified using the aria-labelledby attribute
//used by for example screen readers. In our application, this is not needed.
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
HtmlTextWriter htw = new HtmlTextWriter(sw);
base.Render(htw);
htw.Flush();
string replaceHtml = GetReplaceHtml();
string replaceHtmlAttr = GetReplaceHtmlAttr();
sb.Replace(replaceHtml, string.Empty).Replace(replaceHtmlAttr, string.Empty);
output.Write(sb.ToString());
}
else
{
base.Render(output);
}
}
private string GetReplaceHtmlAttr()
{
return " aria-labelledby=\"" + this.ClientID + "_label\"";
}
private string GetReplaceHtml()
{
var sb = new StringBuilder();
sb.Append("<div id=\"" + this.ClientID + "_label\" style='display:none'>");
if (this.Field != null)
{
sb.Append(SPHttpUtility.HtmlEncode(this.Field.Title));
}
else
{
sb.Append(SPHttpUtility.HtmlEncode(SPResource.GetString("RTELabel", new object[0])));
}
sb.Append("</div>");
return sb.ToString();
}
private bool IsEdit()
{
return SPContext.Current.FormContext.FormMode == SPControlMode.Edit || SPContext.Current.FormContext.FormMode == SPControlMode.New;
}
}
然后您的pagelayout会使用此代码,如下所示:
<YourPrefix:SlimRichHtmlField ID="RichHtmlField1" HasInitialFocus="false" MinimumEditHeight="200px" FieldName="PublishingPageContent" runat="server" />
答案 1 :(得分:0)