SaaS CMS has officially launched! Learn more now.

Sort pages year and then months


I'm trying to sort events in my calendar on the same way as the most blogs sort. All the events are pages that are children to my CalendarContainer-page.

|_ Januari
|_ February

I don't really know where to begin. Can anyone give me any advice on what to begin with?

Feb 22, 2010 9:19

You want to automatically place pages under their correct year and month like the blog does? If so, you can take a look at the blogs HttpModule (EventHandlers in the EPiServer.Blog.dll) with Reflector. What it does is attach itself to some EPiServer page events:


private void SetupEventListeners(object sender, EventArgs e)
    BlogFactory.DataFactory.CreatingPage += new PageEventHandler(this.CreatingPage);
    BlogFactory.DataFactory.CreatedPage += new PageEventHandler(this.CreatedPage);
    BlogFactory.DataFactory.PublishingPage += new PageEventHandler(this.PublishingPage);

This will only work for newly created pages, or pages that get published. What you can do is create a scheduled job that goes through your site and moves the pages for you into their respective container page, and creates the container page if it does not exist yet.

Hope this helps.



Feb 22, 2010 18:43

I interpret your question differently than Fredrik. You say you have all your events in a container, so you want to display those events sorted by month (on a page template)? In that case I suggest you use LINQ to sort the pages by date, then to group them by month. Feed the groups to a repeater which has a nested repeater in it's item template. So each item in the enclosing repeater will correspond to a group/month and each item in the enclosed repeater will correspond to an event in that month. And in this I assume you have events only from one year in the collection to begin with, otherwise I suppose you could group at another level for year (even though this would be slightly more complicated LINQ-wise because you would have a Grouping to deal with rather than PageDatas).

Feb 23, 2010 8:11

Thank you Frederik, but I solved it with a nestled repeater after a couple of hours of banging my head against the wall. :) I tried to solve it with a PageTree and I tried to send in my own collection instead of using the "PageLink" property but I failed. Do you know if its possible to do that?

Edited, Feb 23, 2010 8:18

I think you would bang your head through the wall trying to get it working with a PageTree. You'd probably have to create your own hierarchial datasource for that. The PageTree has all sorts of funny stuff going on, like using it's own method to figure out whether a page has children or not. So I think you would have all sorts of strange interactions with the real page structure if you tried to create your own in-memory structure just to use it to group things.

Feb 23, 2010 8:24

Magnus: I didn't see your answer when I wrote the response to Frederik. Thanks for the help and that was exactly how I did it.
Ok. Too bad. I like the templates in PageTree. Well well. You can't get everything in life. Thanks again.

Feb 23, 2010 8:37
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.