Creative Web Specialist - An online portfolio and resource site of Warren Buckley

Latest Posts

Jan24th

Playing now with a schedule - XSLT in Umbraco

Author
Warren Buckley
Categories

Hello all,
This is my first real post on my new blog and this solution will hopefully be useful to other people using the Umbraco opensource .NET CMS platform.

The problem:
I need to be able to find out which show is currently playing depending on the day of the week and the time of the day from a schedule in Umbraco.

The solution:
To achieve the same results, I recommend setting up the same structure as me to begin with and then alter the code and move the structure as need be once all is working.

Below is a screenshot of my structure.

I created two document types in Umbraco which are as follows:

  • Name: Day
    • Alias: Day
    • Icon: folder.gif
    • Allowed child nodetypes: Show
    • Generic properties: None
    • Tabs: None
  • Name: Show
    • Alias: Show
    • Icon: doc.gif
    • Allowed child nodetypes:None
    • Tabs: Show
    • Generic properties
      • Name: Start Time 24HR (eg 15:00)
        • Alias: StartTime
        • Type: Textstring
        • Tab: Show
        • Mandatory: Yes
      • Name: End Time 24HR (eg 15:00)
        • Alias: EndTime
        • Type: Textstring
        • Tab: Show
        • Mandatory: Yes
Below is the XSLT solution which I will try and break down and explain. (Note: this code is between the tags)
								

On air:

The variable DateNow is to get the current date, which the variable DayName uses in the GetWeekDay umbraco library function and finally Time is used with FormatDateTime with the DateNow variable.

Then the xsl:for, loops through all shows where the node name matches the DayName variable. So obviously don't rename your day nodes! Once in the loop we get the StartTime and EndTime node properties and put them in the variables.

We create two new variables which use the umbraco library function DateGreaterThan function. Note: to have a DateLessThan just simply switch the dates around in the function.

Finally we check to see if the two DateGreater variables are equal to true (1)

The only problem I come across with this script is that it would not match shows where the end time falls into the next day. For example 22:00 to 05:00. What I did to resolve this was to split the show across the two days. So on Wednesday evening 22:00 to 23:59 then Thursday morning 00:00 to 05:00.

My final gripe was that I could not set the end time to 00:00 for the code to work, so I set it to 23:59 and done a replace anywhere an end time equals 23:59 and replaced it with 00:00

Hopefully this made some sense, but if you have any questions about this solution please feel free to ask me. Warren

2 comments
24th January, 2007
What… no umbraco blog…
25th January, 2007
Hello Bob,
I am using the wordpress platform for the time being, as I want to learn from it and hopefully take it across to the umbraco blog feature.

At the moment I am concentrating on a new version of the website package in the evenings during the week, so setting up and configuring a blog with umbraco could take a while.

Warren
Post a comment »

Comment's have been disabled, due to getting hit badly with comment form spam

My Skill Set

This is a quick list of my skill set to date

  • XHTML
  • CSS
  • Photoshop (Slicing)
  • XSLT
  • ASP.NET
  • Umbraco .NET CMS

My del.icio.us

My Last.FM

I am listening to:

  • Ain't Pretending by CowbellOh Girl29 Jul 2010, 10:37
  • Just Want Your Love by CowbellOh Girl29 Jul 2010, 10:33
  • Oh Girl by CowbellOh Girl29 Jul 2010, 10:31
Warren Buckley is an umbraco MVP 2008/2009 Warren Buckley is an umbraco level 1 certified developer

Photo of Warren Buckley Warren Buckley is a Creative Web Specialist based in Leigh on Sea, Essex , UK.