从主数据库填充的 RTE 中的 Sitecore 创建下拉按钮

标签 sitecore

我正在尝试为 Sitecore 中的富文本编辑器 (RTE) 创建一个下拉按钮,但无法弄清楚如何实现这一点。我想要类似于下面显示的“插入片段”命令的东西,但是下拉列表的来源是由主数据库中的内容驱动的,而不是由 html 编辑器配置文件中的核心项目驱动的。
enter image description here

我发现的最接近的方法是这个 article which describes how to add a button which opens a dialog in the RTE .

另一种选择可能是拥有一个保存处理程序,当在主数据库的某个区域创建/编辑项目时,它可以在核心数据库中创建片段项目。

最佳答案

设置你自己的按钮需要做大量的工作,包括所有的 JS 处理程序。实现您想要的最简单的方法是(如 Ben Holden 所说)是从 Sitecore.Shell.Controls.RichTextEditor.EditorConfiguration 继承。并覆盖 SetupSnippets()方法:

public class EditorConfiguration : Sitecore.Shell.Controls.RichTextEditor.EditorConfiguration
{
    public EditorConfiguration(Sitecore.Data.Items.Item profile)
        : base(profile)
    {
    }

    protected override void SetupSnippets()
    {
        // add in all the snippets from default
        base.SetupSnippets();

        // load your custom snippets
        Sitecore.Data.Database master = Sitecore.Configuration.Factory.GetDatabase("master");
        Sitecore.Data.Items.Item obj1 = master.GetItem("/sitecore/content/shared/snippets");
        if (obj1 == null)
            return;
        foreach (Sitecore.Data.Items.Item obj2 in obj1.Children)
            this.Editor.Snippets.Add(string.IsNullOrEmpty(obj2["Header"]) ? obj2.Name : obj2["Header"], Sitecore.StringUtil.RemoveLineFeeds(obj2["Value"]));
    }
}

然后您可以在 web.config 中设置配置类型(使用 patch include file )
<!--  HTML EDITOR DEFAULT CONFIGURATION TYPE
    Specifies the type responsible for setting up the rich text editor. Can be overriden at profile level. Must inherit from Sitecore.Shell.Controls.RichTextEditor.EditorConfiguration,Sitecore.Client.
    Default value: Sitecore.Shell.Controls.RichTextEditor.EditorConfiguration,Sitecore.Client
-->
<setting name="HtmlEditor.DefaultConfigurationType" value="myCustomDLL.Controls.RichTextEditor.EditorConfiguration, myCustomDLL"/>

然后在指定的目录中创建您的片段。您可能需要在添加片段后刷新浏览器,因为 RTE 中存在一些缓存。

编辑

正如 Ben 正确指出的那样,如果您使用的是 Rich Text Default配置文件然后设置 HtmlEditor.DefaultConfigurationType在配置中将不起作用。配置文件下的核心数据库中的以下项目确定用于“富文本默认”配置文件的配置类型,例如:
/sitecore/system/Settings/Html Editor Profiles/Rich Text Default/Configuration Type

如果您的个人资料包含名为 Configuration Type 的子项然后它将使用它,否则它将使用 config.yml 中指定的默认值。其他配置文件默认不包含此设置项。如果您希望其他配置文件(或自定义配置文件)使用特定(或不同)配置,请确保您的配置文件包含名为 Configuration Type 的项目。模板类型Html Editor Configuration Type .这在多站点场景中可能非常有用。

关于从主数据库填充的 RTE 中的 Sitecore 创建下拉按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21485295/

相关文章:

asp.net - 仅为 Sitecore 中的特定站点嵌入语言

c# - Sitecore DateField 的 DateTime 属性显示错误的日期

Sitecore 日期比较未返回预期结果

Sitecore网站显示页面更新

workflow - Sitecore 工作流程不起作用

asp.net-mvc - 通过其路径获取 Sitecore MVC 中的项目

Sitecore更新渲染引用

c# - Visual Studio 2012 注册标记前缀 "Could not complete the action."

c# - Sitecore、自定义 MVC Controller 和路由

sitecore - 如何使用 Sitecore 中的工作流向原始提交者发送电子邮件?