Sitecore动态数据源位置

Sitecore动态数据源位置,sitecore,datasource,Sitecore,Datasource,我的Sitecore安装中有一些组件可以添加到页面上任意多个占位符中的一个。这些组件渲染的数据源位置可以根据它们添加到站点的占位符进行更改。我开始创建一个处理器,比如 <getRenderingDatasource> <processor patch:after="*[@type='custom']" type="custom" /> </getRenderingDatasource> 我无法获取要将渲染附加到的占位符。是否有任何方法可以获

我的Sitecore安装中有一些组件可以添加到页面上任意多个占位符中的一个。这些组件渲染的数据源位置可以根据它们添加到站点的占位符进行更改。我开始创建一个处理器,比如

<getRenderingDatasource>
        <processor patch:after="*[@type='custom']"  type="custom" />
</getRenderingDatasource>
我无法获取要将渲染附加到的占位符。是否有任何方法可以获取占位符或至少要添加组件的父级


谢谢,这是一个非常好的主意,但是如果您在占位符上配置允许的数据源位置,
GetRenderingDatasourceArgs
无法为您提供所需的数据

我也搜索了querystring&form变量和上下文项,但是在
getRenderingDatasource
管道中没有对占位符的引用

我确实想出了一些可能是解决办法的办法,尽管有点老套

  • getPlaceholderRenderings
    创建处理器。
    GetPlaceholderRenderingsArgs
    将为您提供一个占位符键
  • 将密钥存储在会话变量中(目前我不知道在管道之间传输数据的其他方法)
  • getRenderingDatasource
    处理器中的会话中检索密钥
  • 这是我用来测试它的代码:

    // Add to the getRenderingDatasource pipeline.
    public class GetPlaceholderKey
    {
        public void Process(GetPlaceholderRenderingsArgs args)
        {
            System.Web.HttpContext.Current.Session["Placeholder"] = args.PlaceholderKey;
        }
    }
    
    // Add to the getRenderingDatasource pipeline.
    public class GetAllowedDatasources
    {
        public void Process(GetRenderingDatasourceArgs args)
        {
            Debug.WriteLine(System.Web.HttpContext.Current.Session["Placeholder"]);
        }
    }
    
    当您将渲染添加到占位符中时,此选项有效,但我尚未测试其他场景。

    我可以想象,当您设置已放置在占位符中的渲染数据源时,它将不起作用。

    我不这么认为。该管道的参数假定数据源位置是固定的。我不认为有任何上下文信息可以抓住。不过这个主意很有趣。2) 您可能可以使用HttpContext.Items而不是会话。
    // Add to the getRenderingDatasource pipeline.
    public class GetPlaceholderKey
    {
        public void Process(GetPlaceholderRenderingsArgs args)
        {
            System.Web.HttpContext.Current.Session["Placeholder"] = args.PlaceholderKey;
        }
    }
    
    // Add to the getRenderingDatasource pipeline.
    public class GetAllowedDatasources
    {
        public void Process(GetRenderingDatasourceArgs args)
        {
            Debug.WriteLine(System.Web.HttpContext.Current.Session["Placeholder"]);
        }
    }