RSS Custom Types - Orchard

We look at getting RSS content on our Orchard site and then parsing it using C # to paste it into our own database. To do this, we need RSS to capture every field of our custom type. Right now, when I receive an RSS project, we get the default elements, description, etc., but not fields of this type.

On the other hand, using the import / export module, I can get all the fields of a custom type, but the module does not support queries (which is why we use projections).

Is there a way to get the RSS feed of all fields of a type, but using query / projection?

+4
source share
1 answer

There is no automatic way to do this, but you can write your own module that does this.

What you need to do is add a class that implements the Orchard.Core.Feeds.IFeedItemBuilder interface. The interface itself has only one method that you need to implement - void Populate(FeedContext context) .

Here is a code snippet of how you can implement this method:

 public void Populate(FeedContext context) { context.Response.Contextualize( c => { foreach (var feedItem in context.Response.Items.OfType<FeedItem<ContentItem>>()) { var contentItem = feedItem.Item; foreach (var part in contentItem.Parts) { // extract data you're interested in from parts foreach (var field in part.Fields) { // extract data you're interested in from fields feedItem.Element.SetElementValue("description", "Text to output to RSS"); } } } }); } 

context.Response.Items contains all the elements that will be displayed in RSS. The hard part here is to find out what kind of data you want to display in RSS, since there are many different parts with many different fields. And they all have different property names that you would like to display on RSS.

So my suggestion is to check if the contentItem in the above example contentItem your custom type. If so, add it and use your own field names to populate the description this feedItem .

+5
source

All Articles