Search code examples
rsssitecoretreelist

Using Treelist Values to Query a Sitecore Item


I have an item named All Recipes that contains recipes named R1, R2, and R3. I have another item named My Recipes that has a treelist field named Recipes and it contains selected values R2 and R3 from the All Recipes item. The query I'm trying to write is for the Items field of an RSS Feed.

What is the query syntax to show the items in All Recipes that appear in the Recipes field of My Recipes?


Solution

  • It can't be done with a Sitecore Query. Instead, create a custom feed class that extends Sitecore.Syndication.PublicFeed and override GetSourceItems(). Here's an example:

    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;
      }
    }
    


    Inside your RSS Feed's Type field, under the Extensibility section, input the class path and assembly for your custom class:

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


    Leave the RSS Feed's Items field empty since this custom class takes its place.