Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Mike 35 posts 100 karma points
    Sep 09, 2012 @ 12:56
    Mike
    1

    Razor example: PDCalendar

    I'm not very good with XSLT, so I gave my shot at a Razor Example.  It's relatively basic, but you can see how to get values from a pdcalendar (@alias=event) using Razor.  I probably could have used a recursive helper function instead of the multiple loops and could use help doing that....  but all-in-all this will work and return a <ul> for every day for August 2012.

    @inherits umbraco.MacroEngines.DynamicNodeContext
    @using PDCalendar;
    @using System.Xml;


    @{
      //initiate the calendar 
      var cal new PDCalendar.library();
      
      //get the events their respective dates (use params...)
      System.Xml.XPath.XPathNodeIterator calIterator cal.GenerateDates("8/1/2012""8/31/2012""event");
      //print out the xml from pdcalendar
      //<p>@calIterator.Current.InnerXml</p>
      
      //create XML document and load it
      XmlDocument calXml new XmlDocument();
      calXml.LoadXml(@calIterator.Current.InnerXml);
      
      //first levelroot  -2nd levelnode wdate attrib  -3rd levelevent wnode "id"
      <ul>
      @foreach (XmlNode child in calXml.ChildNodes)
      
        foreach (XmlNode grandchild in child.ChildNodes)
        {
          @<li>@grandchild.Attributes["date"].Value
          if (grandchild.ChildNodes.Count 0
          {
            @<ul>
            foreach (XmlNode greatgrandchild in grandchild.ChildNodes)
            {
              @<li>
              @umbracoNodeId:  @greatgrandchild.Attributes["id"].Value<br />
              var calitem @Model.NodeById(@greatgrandchild.Attributes["id"].Value);
              XmlDocument xmlpdc new XmlDocument();
              //my field alias is "event"but you can change below to whatever yours is...
              xmlpdc.LoadXml(@calitem.GetProperty("event").Value);
              XmlNode pdcroot xmlpdc.DocumentElement;
              @PDCstartdate@pdcroot.SelectSingleNode("//pdcstart").LastChild.InnerText <br />
              @</li>
            }
            @</ul>
           }
          @</li>
        
      }
      </ul>
    }


     

Please Sign in or register to post replies

Write your reply to:

Draft