自定义 Sitecore 内容编辑器中的快速信息部分

问题描述 投票:0回答:3

是否可以自定义内容编辑器中的快速信息部分以显示有关该项目的其他信息? 谢谢

sitecore
3个回答
2
投票

我认为这会很棘手。如果您查看

Sitecore.Shell.Applications.ContentManager.Editor
(在 Sitecore.Client.dll 中),您会看到有一个
RenderQuickInfo
方法。 HTML 被手动拼凑在一起,并作为文字控件添加到 EditorFormatter 对象中。所有涉及的类都紧密集成到应用程序中 - 没有易于识别的自定义点。

有一些与内容编辑器的渲染相关的管道,

  • 渲染内容编辑器
  • 获取内容编辑器字段
  • 获取内容编辑器皮肤

但我不认为这些会提供一个简单的方法。

总的来说,我一直认为,如果 Sitecore 没有使应用程序的一部分易于定制,那么他们可能是故意这样做的。


1
投票

一个选择可能是更多的 js 方法。整个内容编辑器都在 dom 中,尽管是嵌套的。它略有不同,但突出了这个概念(http://blog.boro2g.co.uk/ever-edited-sitecore-web-db-mistake/)。

我建议,如果你愤怒地使用下面的示例,你可以让 xpath 变得更好 - 这只是从 chrome 开发工具中窃取的。

作为示例:将以下脚本粘贴到 content manager.aspx 文件中,您可以访问某些元素:

<script type="text/javascript">     
    window.onload=function(){ 
        var text = getElementByXpath('//*[@id="EditorPanel"]/table/tbody/tr/td/table/tbody/tr[2]/td[1]');
        if (text) {
            text.innerText = "hi";
        } else {                
        }
    };        
    function getElementByXpath(path) {
        return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
    }
</script>    

然后您可以更新文本(参见屏幕截图): quickinfo 打招呼


0
投票

这个问题被问到近 10 年后,我也被问到同样的问题。

我调查了

renderContentEditor
管道并提出了解决方案:

public class ExtendQuickInfoSection
{
    private const string QuickInfoStartTag = "<table class='scEditorQuickInfo'>";
    private const string QuickInfoEndTag = "</table>";
    private const string AdditionalRowTemplate = "<tr><td>{0}:</td><td>{1}</td></tr>";

    public void Process(RenderContentEditorArgs args)
    {
        if (args.Item == null || args.Parent == null)
            return;

        try
        {
            LiteralControl quickInfoSection;

            if (FindQuickInfo(args.Parent, "QuickInfo_" + args.Item.ID.ToShortID(), out quickInfoSection))
            {
                ExtendQuickInfo(args, quickInfoSection);
            }
        }
        catch (Exception exc)
        {
            Log.Error("Exception in 'ExtendQuickInfoSection.Process' of item " + args.Item.ID, exc, this);
        }
    }

    private static void ExtendQuickInfo(RenderContentEditorArgs args, LiteralControl quickInfoSection)
    {
        var text = quickInfoSection.Text;

        var startIndex = text.IndexOf(QuickInfoStartTag, StringComparison.CurrentCulture);
        if (startIndex > -1)
        {
            var endIndex = text.IndexOf(QuickInfoEndTag, startIndex + QuickInfoStartTag.Length, StringComparison.CurrentCulture);

            if (endIndex > -1)
            {
                var doc = new HtmlDocument();
                var originalHtml = text.Substring(startIndex, endIndex + QuickInfoEndTag.Length - startIndex);
                doc.LoadHtml(originalHtml);
                var tableElement = doc.DocumentNode.ChildNodes[0];
                AddExtraRowToQuickInfoTable(tableElement, "Last Updated", args.Item.Statistics.Updated.ToString("yyyy-MM-dd HH:mm"));
                AddExtraRowToQuickInfoTable(tableElement, "Last Updated By", args.Item.Statistics.UpdatedBy);
                quickInfoSection.Text = text.Replace(originalHtml, doc.DocumentNode.OuterHtml);
            }
        }
    }

    private static void AddExtraRowToQuickInfoTable(HtmlNode tableElement, string header, string value)
    {
        tableElement.ChildNodes.Append(HtmlNode.CreateNode(AdditionalRowTemplate.FormatWith(header, value)));
    }

    private static bool FindQuickInfo(Control control, string sectionId, out LiteralControl quickInfoSection)
    {
        var literalControl = control as LiteralControl;

        if (literalControl != null)
        {
            if (literalControl.Text != null && literalControl.Text.Contains($"id=\"{sectionId}\""))
            {
                quickInfoSection = literalControl;
                return true;
            }
        }
        else
        {
            foreach (Control child in control.Controls)
            {
                if (FindQuickInfo(child, sectionId, out quickInfoSection))
                    return true;
            }
        }

        quickInfoSection = null;
        return false;
    }
}

我写了一篇博文,详细解释了为什么以及如何完成:

扩展 Sitecore 内容编辑器的“快速信息”部分

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.