我希望能够右键单击 Sitecore 中的内容项,然后在上下文菜单中选择“运行我的应用程序”之类的内容。然后在运行的应用程序中,我需要能够引用右键单击的内容项。这可能吗?
最佳答案
是的,您可以做到这一点,它并不像听起来那么难。
您想要放入核心数据库并打开内容编辑器。右键菜单在 sitecore/content/Applications/Content Editor/Context Menus/Default
中定义该文件夹中的项目是您右键单击树中的项目时看到的内容。因此,您可以使用菜单项模板添加一个新项目。
如果您查看现有的,大多数都会向 Sitecore 桌面发送消息。这些消息是/App_Config/Commands.config 中定义的命令。我看不到其中任何会启动另一个 Sitecore 应用程序的内容,因此您需要创建一个新命令来执行此操作。要创建一个,只需继承 Sitecore.Shell.Framework.Commands.Command
类即可。它传入一个 CommandContext ,它将保存一个 Items 集合。
public class DemoCommand: Command
{
#region Overrides of Command
/// <summary>
/// Executes the command in the specified context.
/// </summary>
/// <param name="context">The context.</param>
public override void Execute(CommandContext context)
{
Assert.ArgumentNotNull(context, "context");
var parameters = new NameValueCollection();
if (context.Items != null && context.Items.Length == 1)
{
var item = context.Items[0];
parameters["id"] = item.ID.ToString();
}
Context.ClientPage.Start(this, "Run", parameters);
}
#endregion
public CommandState QueryStat(CommandContext context)
{
Assert.ArgumentNotNull(context, "context");
return CommandState.Enabled;
}
protected static void Run(ClientPipelineArgs args)
{
Assert.ArgumentNotNull(args, "args");
SheerResponse.CheckModified(false);
SheerResponse.Broadcast(
SheerResponse.ShowModalDialog(
"[Path to your application here]"
),
"Shell");
}
}
要获取传递的项目,请在消息调用中传递变量 $Target。
因此菜单项中的消息字段将类似于:
item:runMyApplication(id=$Target)
希望这是有道理的:)
关于sitecore - 在 Sitecore 中,如何通过右键单击内容项来打开自定义 Sitecore 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16920397/