【问题标题】:How does sitecore's treeviewex get associated with the javascripts?sitecore 的 treeviewex 如何与 javascript 相关联?
【发布时间】:2015-11-18 12:02:00
【问题描述】:

我目前正在尝试在 sitecore 中创建一个控件,就像 treeviewex 一样。

但我不清楚我将如何像 sitecore 那样包含 javascript。

如果有人能指出我正确的方向,我将不胜感激,谢谢:)

/罗宾

【问题讨论】:

    标签: javascript treeview sitecore controls


    【解决方案1】:

    您可以创建自己的处理器并将其添加到renderContentEditor 管道中。你可以在这篇博文中找到关于Adding custom Javascript and Stylesheets in the Content Editor的信息和代码

    创建一个新的处理器类:

    public class InjectScripts
    {
        private const string JavascriptTag = "<script src=\"{0}\"></script>";
        private const string StylesheetLinkTag = "<link href=\"{0}\" rel=\"stylesheet\" />";
    
        public void Process(PipelineArgs args)
        {
            AddControls(JavascriptTag, "CustomContentEditorJavascript");
            AddControls(StylesheetLinkTag, "CustomContentEditorStylesheets");
        }
    
        private void AddControls(string resourceTag, string configKey)
        {
            Assert.IsNotNullOrEmpty(configKey, "Content Editor resource config key cannot be null");
    
            string resources = Sitecore.Configuration.Settings.GetSetting(configKey);
    
            if (String.IsNullOrEmpty(resources))
                return;
    
            foreach (var resource in resources.Split('|'))
            {
                Sitecore.Context.Page.Page.Header.Controls.Add((Control)new LiteralControl(resourceTag.FormatWith(resource)));
            }
        }
    }
    

    然后在处理器中打补丁:

    <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
       <sitecore>
         <pipelines>
           <renderContentEditor>
             <processor patch:before="*[1]" type="HideDependentFields.SC.Pipelines.RenderContentEditor.InjectScripts, HideDependentFields.Types" />
           </renderContentEditor>
         </pipelines>
       </sitecore>
    </configuration>
    

    【讨论】:

    • 这正是我希望的,但不知道该怎么做,谢谢。我不想更改任何 sitecore 的文件,所以这是完美的
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-05-06
    • 1970-01-01
    • 2011-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多