Click here to Skip to main content
Licence CPOL
First Posted 14 Jun 2010
Views 4,178
Bookmarked 0 times

N2CMS Templates RSS Feed Fix

By | 14 Jun 2010 | Technical Blog
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 give the error: Cannot use filters when using MaxResults, sorry.
A Technical Blog article. View original blog here.[^]

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

About the Author

Martin Jarvis

Software Developer (Senior)
Freestyle Interactive Ltd
United Kingdom United Kingdom

Member

Follow on Twitter Follow on Twitter
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.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Mobile
Web03 | 2.5.120517.1 | Last Updated 14 Jun 2010
Article Copyright 2010 by Martin Jarvis
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid