【发布时间】:2015-11-18 12:02:00
【问题描述】:
我目前正在尝试在 sitecore 中创建一个控件,就像 treeviewex 一样。
但我不清楚我将如何像 sitecore 那样包含 javascript。
如果有人能指出我正确的方向,我将不胜感激,谢谢:)
/罗宾
【问题讨论】:
标签: javascript treeview sitecore controls
我目前正在尝试在 sitecore 中创建一个控件,就像 treeviewex 一样。
但我不清楚我将如何像 sitecore 那样包含 javascript。
如果有人能指出我正确的方向,我将不胜感激,谢谢:)
/罗宾
【问题讨论】:
标签: javascript treeview sitecore controls
您可以创建自己的处理器并将其添加到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>
【讨论】: