仅为UL中的富文本编辑器中的无序列表添加封闭标记 [英] Add enclosing tag for only UnOrdered list from Rich Text Editor in UL

查看:18
本文介绍了仅为UL中的富文本编辑器中的无序列表添加封闭标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在Sitecore中设置来自Rich Text Editor的UL样式。我正在尝试找出是否有可以从Sitecore的Rich Text Editor添加到所有UL的类。

提前感谢 阿肖克

HTML

最简单的解决方案就是用推荐答案元素包装您的FieldRenderer,并在代码中应用相应的类:

<div class="rich-text">
    <sc:FieldRenderer ID="frRichTextField" runat="server" FieldName="MyFieldName" />
</div>

然后添加一些CSS样式来处理以下内容中的UL:

.rich-text ul {
    /* add in your styling */
}

您还可以使用FieldRenender的beforeafter属性传入您的标记:

<sc:FieldRenderer ID="frRichTextField" runat="server" FieldName="MyFieldName" 
    Before="<div class='rich-text'>" After="</div>" />

编辑:

如果您希望更彻底,则可以将您自己的renderField流水线处理器添加到ensure your control is always wrapped with the required tag中,也可以使用enclosingTag property并修补AddBeforeAndAfterValues流水线:

namespace MyCustom.Pipelines.RenderField
{
    public class AddBeforeAndAfterValues
    {
        public void Process(RenderFieldArgs args)
        {
            Assert.ArgumentNotNull((object)args, "args");
            if (args.Before.Length > 0)
                args.Result.FirstPart = args.Before + args.Result.FirstPart;
            if (args.After.Length > 0)
            {
                RenderFieldResult result = args.Result;
                string str = result.LastPart + args.After;
                result.LastPart = str;
            }
            if (args.EnclosingTag.Length == 0 || args.Result.FirstPart.Length <= 0 && args.Result.LastPart.Length <= 0)
                return;

            // check if a css class paramter has been passed in
            string cssClass = args.Parameters.ContainsKey("class") ? args.Parameters["class"] : String.Empty;
            // add the class to the enclosing tag property
            args.Result.FirstPart = StringExtensions.FormatWith("<{0} class='{1}'>{2}", (object)args.EnclosingTag, cssClass, (object)args.Result.FirstPart);
            args.Result.LastPart = StringExtensions.FormatWith("{0}</{1}>", (object)args.Result.LastPart, (object)args.EnclosingTag);
        }
    }
}

修补Sitecore配置文件:

<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"
               xmlns:set="http://www.sitecore.net/xmlconfig/set/">
  <sitecore>
    <pipelines>
      <renderField>
        <processor type="Sitecore.Pipelines.RenderField.GetLinkFieldValue, Sitecore.Kernel"
                   set:type="MyCustom.Pipelines.RenderField.AddBeforeAndAfterValues, MyCustom.Pipelines" />
      </renderField>
    </pipelines>
  </sitecore>
</configuration>

,然后使用EnclosingTag集调用FieldRenderer并传入您的class参数:

<sc:FieldRenderer ID="frRichTextField" runat="server" FieldName="MyFieldName" 
    EnclosingTag="div" Parameters="class=rich-text" />

这确实不会比使用before/after属性增加多少,而且我通常会尽量避免覆盖默认的Sitecore处理器,以便在升级时省去麻烦。

这篇关于仅为UL中的富文本编辑器中的无序列表添加封闭标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆