Click here to Skip to main content
15,867,568 members
Articles / Web Development / ASP.NET

N2CMS Templates RSS Feed Fix

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
14 Jun 2010CPOL 9K  
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:

C#
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:

C#
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Freestyle Interactive Ltd
United Kingdom United Kingdom
I'm a lead developer for Freestyle Interactive Ltd where we create many wonderful websites built on Microsofts ASP.Net and Ektron CMS.

I've been developing .Net applications (both Windows and Web) since 2002.

Comments and Discussions

 
-- There are no messages in this forum --