Developer forum

Forum » Templates » Razor template for a calendar

Razor template for a calendar

Jens Mouritzen
Jens Mouritzen
Reply

Hi guys
I'm very new to Razor templates. I got a event booking site that needs an event calendar sorted by month. The events are made with items and display with the itempublisher (it's a DW9 solution). The hierarchy/loop would look like this (see image 1).

Right now it loops the items themselve, but it needs to loop the months from the date field in the item and iterate the items inside that loop. (see code on image 2)

The calendar can also be seen on http://csb.dw9.dynamicweb-cms.com/calendar

image1.png image2.png

Replies

 
Jens Mouritzen
Jens Mouritzen
Reply

Anyone who have an idea for this?

 
Nicolai Pedersen
Reply

Hi Jens

I Have 2 suggestions

  1. Use a LINQ to group the events into lists of events based per month. If you are new in .NET it might be difficult - Google how to group objects by month using LINQ.
  2. The simpler alternative is to create a variable callled i.e. "PreviousMonth" and set it to 0 outside the loop. Inside the loop check if currentEvent.month is different from the previous month and write out the header and update the previoues month variable.

BR Nicolai

 
Jens Mouritzen
Jens Mouritzen
Reply

Would you mind making an example on suggestion number 2?

 

You must be logged in to post in the forum