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.
2010 |_ Januari |_ February2009 |_Januari |_March
I don't really know where to begin. Can anyone give me any advice on what to begin with?
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.
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).
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?
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.
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.