Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

N2CMS Templates RSS Feed Fix

0.00/5 (No votes)
14 Jun 2010 2  
N2CMS Templates RSS Feed Fix

N2CMS comes with some pretty fully featured examples, the most useful to me is the N2.Templates example site. Unfortunately, as it stands, the RSS feed is broken and gives the error:

Cannot use filters when using MaxResults, sorry.

Fortunately, a fix can be found in the N2.Templates.Mvc project. You just need to replace the following functions in N2.Templates.Items.RssFeed:

public virtual IEnumerable<ISyndicatable> GetItems()
{
  foreach (ISyndicatable item in N2.Find.Items
      .Where.Detail(SyndicatableDefinitionAppender.SyndicatableDetailName).Eq(true)
      .Filters(GetFilters())
      .MaxResults(NumberOfItems)
      .OrderBy.Published.Desc
      .Select())
  {
      yield return item;
  }
}

private ItemFilter[] GetFilters()
{
  ItemFilter[] filters;
  if (FeedRoot != null)
      filters = new ItemFilter[] { new TypeFilter(typeof(ISyndicatable)), 
		new AccessFilter(), new ParentFilter(FeedRoot) };
  else
      filters = new ItemFilter[] { new TypeFilter(typeof(ISyndicatable)), 
		new AccessFilter() };
  return filters;
}

with:

public virtual IEnumerable<ISyndicatable> GetItems()
{
  var filter = new AccessFilter();
  var q = N2.Find.Items.Where.Detail
	(SyndicatableDefinitionAppender.SyndicatableDetailName).Eq(true);
  if (FeedRoot != null)
      q = q.And.AncestralTrail.Like(Utility.GetTrail(FeedRoot) + "%");
  foreach (ContentItem item in q
          .OrderBy.Published.Desc
          .Select().Take(NumberOfItems))
  {
      var syndicatable = item as ISyndicatable;
      if (syndicatable != null && filter.Match(item))
      {
          yield return syndicatable;
      }
  }

And add ‘using System.Linq’ to the top of the file.

Easy… though it would be nice to see this fix, make it into the trunk repository!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here