views:

59

answers:

3

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?

A: 

If you're writing this in xslt, you can use sc:listfielditems('fieldname',$item) to get a node-set of the items in the treelist, which you can then iterate through using for-each.

If you're writing this in .net, I don't know - but I know a guy who does, and I'll send this his way.

adam
I'm really looking for a query I can put into the Items field of an RSS Feed. Something in the form of "query:/sitecore/content/home/*[QUERY TO GET ITEMS FROM TREELIST HERE]".
kirk.burleson
A: 

Are you using SQL Server? The Sitecore cookbooks advise you to do something like this:

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

The reasoning is that querying for /home/whatever/allrecipes is optimized by the provider, whereas a complex query checking for MyRecipes would be more costly.

Reference: http://sdn.sitecore.net/Reference/Using%20Sitecore%20Query.aspx

Bryan
+1  A: 

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.

kirk.burleson