sitecore - 在 Sitecore 中,如何通过右键单击内容项来打开自定义 Sitecore 应用程序?

标签 sitecore sitecore6

我希望能够右键单击 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/

相关文章:

Sitecore 索引重建实践

sitecore - 从 Sitecore 6.5 中的自定义字段获取当前项目

c# - Sitecore 获取所有语言的列表

razor - 编辑模式下的 Sitecore 下拉列表

sitecore - Sitecore 工作流程和标准值继承的烦人问题

Sitecore - 创建文件下载链接

c# - 如何以编程方式在 sitecore 中设置 Treelist 的值

sitecore - 多个相同渲染时渲染参数不正确

asp.net - 请求验证 - 在 SiteCore 中如何以及为何禁用它?

c# - 在项目中的所有模板中设置 Sitecore 字段共享