Advertisement
Guest User

Event List Razor Macro

a guest
Apr 12th, 2013
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.11 KB | None | 0 0
  1. @using System;
  2. @using umbraco.MacroEngines;
  3.  
  4. @inherits umbraco.MacroEngines.DynamicNodeContext
  5. @{
  6.     int eventCategoryFolderId;
  7.    
  8.     if(!int.TryParse(Parameter.EventCategoryFolderId, out eventCategoryFolderId))
  9.     {
  10.         // not specified? use homepage
  11.         eventCategoryFolderId = -1;
  12.     }
  13.    
  14.     dynamic eventCategoryFolder = new DynamicNull();
  15.     dynamic eventNodes = new DynamicNull();
  16.     try
  17.     {
  18.         eventCategoryFolder = Model.NodeById(eventCategoryFolderId);
  19.         eventNodes = eventCategoryFolder.Descendants("Event").Where("Visible && endDate > DateTime.Now");
  20.     }
  21.     catch(Exception ex)
  22.     {
  23.         <h3>There was some sort of problem. Possibly an invalid category... Drats...</h3>
  24.     }
  25. }
  26.  
  27. @if (eventNodes.Any())
  28. {
  29.     <h2>@eventCategoryFolder.Name</h2>
  30.     <ul>
  31.         @foreach (var eventItem in eventNodes.OrderBy("startDate desc"))
  32.         {  
  33.             <li>
  34.                 <div>
  35.                     <h3><a href="@AutoFolders.XsltExtensionLibrary.NiceUrl(eventItem.Id)">@eventItem.Name</a></h3>
  36.                     <small>@eventItem.startDate.ToString("MMMM dd") @Html.Raw(" - ") @eventItem.endDate.ToString("MMMM dd")</small>
  37.                 </div>
  38.                 <div class="clear"></div>
  39.             </li>
  40.         }
  41.     </ul>
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement