Two Significant Modules: CCK & Views
Custom Data
Not everything you want to do on Drupal is going to involve pictures and text fields. What if you want something more complex with custom relationships that you want to define? That's what CCK and Views are for. CCK allows you to create custom data structures and then Views help you display them.
Overview of today's task
We're going to create some custom tables for a Photography school.
We will create some new Content Types and some new Taxonomy so that we can display a table called Upcoming Classes. We'll do the table next week. The finished table, if you were to handcode it in HTML, might look like the table below. But you want users to be able to search on your data and display only the data they're interested in. You also want to have them search on instructors, and classes, without entering the data in two different places.
What we want to see in our drupal site - the Course links go to a description of the course, the instructor links go to more detail about the instructor:
Upcoming Classes
| Date / Time | Course | Location | Instructor |
|---|---|---|---|
| 6/10/2008 4 pm | Photographing Water Views | BayView Cafe | Anne Avery |
| 6/24/2008 10 am | Digital Darkroom | Haggard Hall 155 | Robin Smith |
| 7/4/2008 8 pm | TimeLapse Photography: Fireworks | BayView Cafe | Brian Bellevue |
Content Construction Kit
The Content Construction Kit is used to create custom databases. If you had a stamp collection and wanted to list each stamp, its dimensions, country of origin, original price, date acquired ... etc, CCK would be the way to set up this data. You use CCK to set up a new kind of node, in Drupal speak.
Resources
Here are some modules that go along with CCK that you might find handy:
- Date - for putting dates in your cck data
- Email - for putting email addresses in your cck data - includes turning them into "mail-to" links, validating the addresses, and encryption
- Image field - if you want images in your cck data (Use ImageCache if you need thumbnail generation)
- link - for including hyperlinks in your data - can also decide how you want the link to open once it's pressed
Demo
See CCK step by step instructions
Views
Views pulls together your custom content and displays it - as a table or list of nodes; in a block or page.
From drupal.org:
You need Views if:
- You like the default front page view, but you find you want to sort it differently.
- You like the default taxonomy/term view, but you find you want to sort it differently; for example, alphabetically.
- You use /tracker, but you want to restrict it to posts of a certain type.
- You like the idea of the 'article' module, but it doesn't display articles the way you like.
- You want a way to display a block with the 5 most recent posts of some particular type.
- You want to provide 'unread forum posts'.
- You want a monthly archive similar to the typical Movable Type/Wordpress archives that displays a link to the in the form of "Month, YYYY (X)" where X is the number of posts that month, and displays them in a block. The links lead to a simple list of posts for that month.
And then my favorite - you want to display the data in a sortable table (like a spreadsheet).
Get your content created this week and next week we'll investigate the formidable and powerful Views module and create our table of Upcoming Classes.
Resources
Views Documentation on Drupal.org
Here are some modules that go along with Views that you might find handy (you can look these up on drupal.org)
- Views Calc - if you need simple calculations in your fields instead of user input
- Views Embed Form - if you need to embed a form in your view - say a submit button for a shopping cart
- Draggable Views / Views Accordion - these are both ways to display styles and functionality to your views
- Views Calendar - if you want to display your dates in calendar formats
