【问题标题】:Using Treelist Values to Query a Sitecore Item使用 Treelist 值查询 Sitecore 项目
【发布时间】:2010-03-16 21:04:49
【问题描述】:

我有一个名为“所有食谱”的项目,其中包含名为 R1、R2 和 R3 的食谱。我有另一个名为“我的食谱”的项目,它有一个名为“食谱”的树列表字段,它包含从“所有食谱”项目中选择的值 R2 和 R3。我正在尝试编写的查询是针对 RSS 提要的 Items 字段。

显示“我的食谱”的“食谱”字段中出现的“所有食谱”中的项目的查询语法是什么?

【问题讨论】:

    标签: rss sitecore treelist


    【解决方案1】:

    这不能通过 Sitecore 查询来完成。相反,创建一个扩展 Sitecore.Syndication.PublicFeed 并覆盖 GetSourceItems() 的自定义提要类。这是一个例子:

    public class MyCustomFeed : Sitecore.Syndication.PublicFeed
    {
      public override IEnumerable<Sitecore.Data.Items.Item> GetSourceItems()
      {
        Sitecore.Data.Database master = Sitecore.Configuration.Factory.GetDatabase("master");
        Item contentFolder = master.GetItem("/sitecore/content/Home/MyContentFolder");
    
        //Do your processing here to get your feed items
    
        //I'm just grabbing what's in the content folder, but it could be something complex.
        ChildList cl = contentFolder.GetChildren();
    
        return cl;
      }
    }
    


    在 RSS Feed 的 Type 字段中,在 Extensibility 部分下,输入自定义类的类路径和程序集:

    Utility.SitecoreLibrary.RSS Folder.MyCustomFeed, Utility.SitecoreLibrary


    将 RSS Feed 的 Items 字段留空,因为这个自定义类将取代它。

    【讨论】:

      【解决方案2】:

      如果您在 xslt 中编写此代码,您可以使用 sc:listfielditems('fieldname',$item) 获取树列表中项目的节点集,然后您可以使用 for-each 对其进行迭代。

      如果你用 .net 写这篇文章,我不知道 - 但我认识一个这样做的人,我会按照他的方式发送。

      【讨论】:

      • 我真的在寻找可以放入 RSS Feed 的 Items 字段的查询。 “query:/sitecore/content/home/*[QUERY TO GET ITEMS FROM TREELIST HERE]”形式的东西。
      【解决方案3】:

      我无法评论上面亚当的帖子,所以我将作为答案离开:没有名为 sc:listfielditems 的 Sitecore 函数/方法。你能仔细检查你的代码吗?

      【讨论】:

        【解决方案4】:

        您使用的是 SQL Server 吗? Sitecore 食谱建议您执行以下操作:

        MyItems = GetSomeItems("/home/whatever/allrecipes");
        foreach(Item item in MyItems)
        {
            if(item is in MyRecipes)
                do something
        }
        

        原因在于,对 /home/whatever/allrecipes 的查询已由提供程序优化,而对 MyRecipes 的复杂查询检查成本会更高。

        Reference.

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-03-12
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多