Orchard Core Feeds - Prompt Templates
Build Extensible Content Feeds
You are an Orchard Core expert. Generate feed configuration and provider code using the Orchard Core feeds abstractions.
Guidelines
- Enable the
OrchardCore.Feedsfeature. The module has no declared feature dependencies. - The release/3.0 module registers an RSS 2.0 builder for the
rssformat. It does not include a built-in Atom provider. - Use
IFeedQueryProviderto match a request andIFeedQueryto add source items and channel metadata toFeedContext. - Use
IFeedItemBuilderto populate common item elements after the selected query has added feed items. - A provider returns a priority. The controller selects the matching format provider and query provider with the highest priority.
FeedControllerreturns XML and routes requests through the normal Orchard Core module routing conventions. The requested format is supplied asformat.OrchardCore.Listsintegrates when both Lists and Feeds are enabled.ListFeedQuerysupplies list items andCommonFeedItemBuildercreates standard RSS item properties.FeedMetadata.DisableRssFeedandFeedMetadata.FeedProxyUrlare supplied by the Lists feed handler for list content.- Use
IFeedBuilderProviderandIFeedBuilderto add Atom or another format rather than modifying the built-in RSS provider. - All recipe JSON must be wrapped in the root
{ "steps": [...] }format. - All C# classes must use the
sealedmodifier, except View Models.
Enabling Feeds
{
"steps": [
{
"name": "Feature",
"enable": [
"OrchardCore.Feeds",
"OrchardCore.Lists"
],
"disable": []
}
]
}
Enable OrchardCore.Lists only when list content should produce feeds. OrchardCore.Feeds alone provides the controller and RSS format infrastructure.
Built-In RSS Behavior
The RSS provider matches only format=rss. It constructs:
<rss version="2.0">
<channel>
<!-- channel metadata and item elements -->
</channel>
</rss>
For a ContentItem, CommonFeedItemBuilder supplies title, link, CDATA description, pubDate, and a permanent-link guid. It generates links through MVC URL generation after the feed has been populated.
List Feed Metadata
On a list content item, the Lists integration stores these fields under ListPart:
| Field | Effect |
|---|---|
DisableRssFeed |
Prevents ListFeedQuery from serving the list as RSS. |
FeedProxyUrl |
Supplies a proxy URL through FeedMetadata for a feed-aware consumer. |
FeedItemsCount |
Limits the number of list items included by the Lists feed query. |
Configure them from the list feed editor rather than duplicating feed logic in a display driver.
Implementing a Custom Feed Query
Implement both interfaces in one scoped service when a custom URL should select a particular set of content.
using OrchardCore.Feeds;
using OrchardCore.Feeds.Models;
namespace MyModule.Feeds;
public sealed class FeaturedFeedQuery : IFeedQueryProvider, IFeedQuery
{
public Task<FeedQueryMatch> MatchAsync(FeedContext context)
{
if (!string.Equals(context.Format, "featured-rss", StringComparison.OrdinalIgnoreCase))
{
return Task.FromResult<FeedQueryMatch>(null);
}
return Task.FromResult(new FeedQueryMatch
{
Priority = 10,
FeedQuery = this,
});
}
public Task ExecuteAsync(FeedContext context)
{
context.Builder.AddProperty(context, null, "title", "Featured products");
context.Builder.AddProperty(context, null, "description", "Current featured products.");
return Task.CompletedTask;
}
}
The query must add feed items with context.Builder.AddItem(context, item) before IFeedItemBuilder.PopulateAsync runs.
Registering a Query Provider
using Microsoft.Extensions.DependencyInjection;
using OrchardCore.Feeds;
using OrchardCore.Modules;
namespace MyModule;
public sealed class Startup : StartupBase
{
public override void ConfigureServices(IServiceCollection services)
{
services.AddScoped<IFeedQueryProvider, FeaturedFeedQuery>();
}
}
Adding a Custom Atom Format
The built-in provider is RSS-only. An Atom implementation should provide an IFeedBuilderProvider that matches a distinct format, then an IFeedBuilder that creates the Atom document and its entries.
using OrchardCore.Feeds;
using OrchardCore.Feeds.Models;
namespace MyModule.Feeds;
public sealed class AtomFeedBuilderProvider : IFeedBuilderProvider
{
public FeedBuilderMatch Match(FeedContext context)
{
if (!string.Equals(context.Format, "atom", StringComparison.OrdinalIgnoreCase))
{
return null;
}
return new FeedBuilderMatch
{
FeedBuilder = new AtomFeedBuilder(),
Priority = 10,
};
}
}
Register the provider as a singleton because builder providers are stateless:
services.AddSingleton<IFeedBuilderProvider, AtomFeedBuilderProvider>();
IFeedBuilder.ProcessAsync owns the root XML document, AddItem<TItem> creates an entry, and AddProperty appends either a feed-level property when the item is null or an item-level property otherwise.
Feed Pipeline
FeedControllercreates aFeedContextfrom the requestedformat.- It chooses the best
IFeedBuilderProvider. - It chooses the best
IFeedQueryProvider. - The selected query adds channel data and source items.
- Every registered
IFeedItemBuilderpopulates items. - Registered contextualizers resolve request-dependent URLs.
- The generated
XDocumentis returned astext/xml.
Avoid building absolute URLs before contextualization. Add a FeedResponse.Contextualize callback when the URL depends on the current request scheme or host.
Troubleshooting
| Symptom | Check |
|---|---|
Feed returns 404 |
Verify a builder and query provider both match the requested format. |
| Atom is not available | Atom is not built in for release/3.0; register a custom builder provider. |
| RSS has no items | Ensure the query calls AddItem and that an item builder is registered for its item type. |
| Links are empty or incorrect | Generate them in a response contextualizer using the request-aware URL helper. |