Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
So far in this course, we have used dates twice, the first time was when we setup the People Content Type. There, we included a CCK field for the Date of Birth. The second time was when we set up the Event Content Type and used another CCK field to show when that event would take place. We then presented those dates in text format on the screen. But we don't usually look at dates in that form, do we? Now, we often find them easier to understand when we put them on a calendar. Fortunately, the author of the Date Module, Karen Stevenson has also written a really nice module to output date information in this calendar format.
Karen was also very involved in the development of the CCK module by the way, and the Calendar module integrates beautifully with both it and Views. We have already downloaded and installed the Calendar module. If you need any help doing so, see the section of my Lynda.com Drupal Essential Training course, expanding your site's capabilities with modules. Setting up calendars turns out to be a pretty complicated affair, but the good news is you don't have to do it from scratch. Included with the Calendar and Date modules are some built-in views.
All you have to do is go into those views and turn them on. In addition, the Date module we already installed includes a module called Date Tools that makes our job easier. Like most people who use these modules, we are going to take advantage of these tools rather than creating these calendar views strictly from scratch. The first thing we need to do is to turn on the modules. To do so, go to Administer, Site Building, and Modules, and then scroll down to the Date and Time Group. As you can see, there are a lot of date and time modules here. We are only going to turn on a few of them. We'll turn on Calendar and then scroll down, and turn on Date tools.
To understand what the rest of these modules do, see the documentation on drupal.org. But for us, that's all we need, so we'll scroll down further and click Save Configuration. Now that we have turned on the Modules, we are going to go through Date Tools and see exactly how it works. We'll set up a new content type using it, and we'll automatically setup a View along with some other nice things like Blocks that go along with that View. To do so, go to Administer, and then you will see Date Tools right here underneath Content Management. Click it, and that brings you to the Date Tools administrative page. Go up to the Tab and click on Date Wizard.
Here we get warned that we actually have to turn on another module. In my opinion, this is an error in the module's programming, because it should have told us this before we ever installed it, easy enough though. We go back to Administer, Site Building, and Modules, scroll down again until we get to that Date and Time group, and turn on that Date Repeat API, there. Now, scroll down, Save Configuration again, and go back to where we were. Once again, that's Administer, Content Management, Date Tools, and Date Wizard.
Good! Now, we are going to setup our new content type. Since we are going to throw this away later, I'm just going to call it temp_date. That's the machine-readable name, so of course you can only use underscores and not spaces. In fact, I'm going to leave all the other settings on their defaults. If you like, you can go back and obviously figure out how they work and what they give you. Scrolling down further, I click Save. What that did was it created a new content type and it also created this new view called calendar_temp_date. The one thing that the Date Tools module can't do is it can't save the view.
So in order to use this, you have to scroll down and click Save. We are not going to make any changes ourselves. Instead we'll take a look and see exactly what the default installation does. So we click Save and we now have our new view. Let's take a look at what it does. If you look along the displays here, you can see it installed a page and a block, and then it has a lot of other displays here. Let's just take a quick look at that page, by going up to this View Calendar page and right-clicking on it, or holding down the Ctrl key on the Mac to open up a new tab with that information.
We will go over to that Tab and voila! Now, I started recording this and adding notes to the site in March. So let's go back a little bit and see what's in our March calendar. There, we now have our new view called calendar_temp_date. Let's take a quick look at it. The first thing to look at is the first thing that we usually add to a view, which is the Filters. It's showing only nodes of the type temp_date that have been published. Let's take a look at that content type temp_date. To do so, go to Administer, Content Management and Content Types, and then click on the temp_date content type down here on the Manage Fields link.
As we can see, it's setup only one additional field, this Date field. We can of course create content of that content type as we usually do by clicking on Create Content and then going to the Content Type name, in this case Temp Date. You can see it's a title, a date, with a From and a To and a body, and that's pretty much it. We are not going to actually create any nodes of that content type. Instead, we are going to go back and edit the view to show some of those events we already setup. To do that, we go to Administer, Site Building and Views. Now we go back to our view, which was called calendar_temp_date, and we edit it.
We now have our view ready to edit, so that it reflects nodes of the content type event rather than that of temp_date. There are three things that you have to change, one is in the Filters group, another is in Fields, and the final is in Arguments. You might remember that the content type was called temp_date, and the date field was simply called Date. As you look at those three groups, you can guess that what they are. This one has temp_date that has to be changed to event. This one has date that has to be changed to event date or whatever we named it and the same is true in the Fields group.
Let's do that now. We first edit the Filter by clicking on Node: Type and scrolling down, changing it to Event, and clicking Update Default Display. The second thing we need to do again is in the Fields, I'm going to remove that Content: Date - From Date by clicking this Rearrange, and scrolling down and just deleting it by clicking on the Delete button. Once again, Update. We now have to re-add in the field that we want. Add the field here, scroll down a little bit until we get to the Content group down here. We have Date, Field Date, From Date, this is the one that we had before because of course the field was called simply Date. We have Date of Birth. That's not what we want.
We do have Date of Event. We'll use the From Date there and click add. I am going to simply leave the defaults here and see how that looks. We can change it later if we like. So Update Default Display, scrolling up again. You might remember how Arguments work. On a page, they show what section of data you are showing. If for example you had done Archives and you wanted to show all of the posts in the month of May, you would use an argument that said show me that month. Well, it's the same here. But right now it's filtering based on this Date field that we don't have anything in. So we click on that and scroll down. We have all of our usual Argument controls here, but we have quite a few more with the Date Module.
Down here, you can say what fields you actually wanted to filter on. I'm going to remove this one and add in Date of Event, From Date. Again, I'm going to leave everything else alone just to see what the defaults look like. Scroll to the bottom, and click Update Default Display. Now, we are ready to see what our calendar looks like. As always, you should scroll up and save before you go any further. That brings us back to our Calendar page. Let's take a look backwards just to make sure that it's not showing us for example the post date for those events. No, we posted in March and there is nothing there. Remember, the two events we had were in November of 2009, and one was in December, let's see.
We click ahead, and there it is. We now have a calendar showing those events. Incidentally, you can see the Arguments working by looking up in the Address Bar here, 2009-11. If we change that to 2009-12 manually like that, we see our December calendar just as we expect. Let's go back and take a look at that view by clicking Edit to see what else we can do with it. Well, it installed a block called Calendar Block. Let's take a look at that block. We do that by going to Administer, Site Building, and Blocks. Scroll to the bottom here, there is our Calendar Block.
Let's move that into the Right Sidebar just to see what it looks like. We do that, and click Save Blocks, and there it is. Let's go ahead to November or December just to see how it changes when there are events there. Again, I click ahead and as you can see, on a day when there is events, those dates will be underlined. If you click on that day, it brings you to a daily calendar, very flexible. Now, I showed you how to do this using Date Tools, but it's kind of a heavyweight solution. First of all, you can't delete the views that it creates.
They appear like the views we discussed in the video Learning from built-in views, so you can only disable them. Likewise, you can't delete the blocks it creates. So I'm going to briefly show you a more lightweight way of doing this. I won't actually go through the process, but it will give you an idea of another way to create calendars without all of this extra stuff. To do so, go to Administer, Site Building, and Views once again. Scroll down until you see this view Calendar. This is something that was installed by the Calendar Module. You would enable it, and then just clone it and name it whatever you want.
Once you are in there, again you could edit it just as I showed you. But as we have things now, the calendar is working beautifully. The last thing I'm going to do is remove that calendar block from here just for now. I go to Administer, Site Building, and Blocks, scroll down until I see that Calendar Block, and just move it to None and Save. Before we go, I want to mention one other way of displaying dates that I'm really excited about. Unfortunately, development of the Drupal Module isn't quite ready as I'm recording this video. I'm hopeful that it will be by the time you see it though.
There is already a stable version for Drupal 5 and it's just a matter of porting it to Drupal 6. It's called the Timeline Module and it takes advantage of some work at the Massachusetts Institute of Technology to create great displays. Let's take a look at a few of them. This page was created using the Timeline Widget. It's not actually in Drupal, but when you install it into Drupal, it looks very much like this. As you can see, it's a Scrolling Timeline. In this case, it shows events around JFK's death. If you click on any of the events, you get information from the node and in fact you could set it to go to that node. Another site that's using the Timeline Module is one from the government, recovery.gov.
This site interestingly is built on Drupal, although it's a very customized version of Drupal. If you scroll to the bottom, you will see again the Timeline, this time implemented in Drupal. We have gotten into some pretty deep waters here, and I think it's clear. We could spend hours wading through the complexities of the Date and Calendar Modules. We shouldn't blame their creators for the complexity though. I once heard Ms. Stevenson, the author of the Modules talk about how difficult it was to handle time-based data and it was simply mind blowing what with time zones, repeating dates, leap years, events that go from one date to another, so forth.
It's really amazing that these modules do as much as they do. And while the interface for the Calendar Module can be very intimidating, the tools that come with it will get you up in running quickly while leaving lots of room for later adjustments.
Get unlimited access to all courses for just $25/month.Become a member
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.