Timetable Example using Dript

Events happening in the community are now at Drupal community events on www.drupal.org.
You are viewing a wiki page. You are welcome to join the group and then edit it. Be bold!

I bet this is the first dript example. I've created a fictitious timetable content using dript and cck. (The site is in Malay however the timetable is in English.) I didn't theme the content so I just let the cck fields display themselves at the bottom of the table. In a real implementation those fields should be hidden.

The objective of the timetable content is that the end user who wants to create a time table don't have to worry about the layout such as the table structure, html, and theme. The person only needs to enter the data. And on the other hand, the administrator don't have to install any other module or to worry about PHP. Hence if the administrator wants to theme it later he or she don't have to worry about the data and do it once for all timetable contents.

The output is something like this:

Monday Tuesday Wednesday Thursday
9.00-10.00 Science Science Math Math
10.00-11.00 English English Science Science
11.00-12.00 Math Malay Lab Civics

Here is how I did it:

1. Install dript and cck modules.

2. Create 'Time Table Day' content type with the following period fields:

  • 9.00 - 10.00
  • 10.00 - 11.00
  • 11.00 - 12.00

3. Create 'Time Table' content type with the following day fields:

  • Monday
  • Tuesday
  • Wednesday
  • Thursday

4. Create four 'Time Table Day' contents with the titles monday to thursday, and fill the period fields with the subjects. Follow the example link above: click on the day links to go to the day contents.

5. Create a 'Time Table' content with the title 'Weekly schedule for 2007', and fill the day fields with the node ids of the respective 'Time Table Day' contents.

6. Paste the following dript code in the body of the 'Time Table' content and submit. My advice is not to press the preview button since the html table may be ripped into half and the page will be rendered badly (Really, I've experienced it with Garland theme).

[driptn
(defun dref (d)
  (strcat "index.php?q=node/" (drupal-read-field 'this d)))

(defun cell (d t)
  (set 'dnid  (drupal-read-field 'this d))
  (drupal-read-field dnid t))
/]
<table>
<tr><th>
<th><a href="[driptne (dref 'monday)/]">Monday</a>
<th><a href="[driptne (dref 'tuesday)/]">Tuesday</a>
<th><a href="[driptne (dref 'wednesday)/]">Wednesday</a>
<th><a href="[driptne (dref 'thursday)/]">Thursday</a>
<tr><th>9.00-10.00
<td>[driptne (cell 'monday '900___1000)/]
<td>[driptne (cell 'tuesday '900___1000)/]
<td>[driptne (cell 'wednesday '900___1000)/]
<td>[driptne (cell 'thursday '900___1000)/]
<tr><th>10.00-11.00
<td>[driptne (cell 'monday '1000___1100)/]
<td>[driptne (cell 'tuesday '1000___1100)/]
<td>[driptne (cell 'wednesday '1000___1100)/]
<td>[driptne (cell 'thursday '1000___1100)/]
<tr><th>11.00-12.00
<td>[driptne (cell 'monday '1100___1200)/]
<td>[driptne (cell 'tuesday '1100___1200)/]
<td>[driptne (cell 'wednesday '1100___1200)/]
<td>[driptne (cell 'thursday '1100___1200)/]
</table>


The following are CCK fields that keep the nodes of the daily time table:

The first part of the code defines two dript functions (dref) and (cell). (dref) is to compose an url to a 'Time Table Day' content. And (cell) to get the subject from a 'Time Table Day' content. (Okay I admit that 'cell' is a little bit misnomer.)

The second part of the code is to generate the time table using html table tags with embedded dript codes. Notice that dript codes escape just like PHP. And notice also the dript codes inside href string values.

I wish content fields could have default values so that each time I want to create a 'Time Table' content I don't have to paste the same code again. But right now we have to live with that. Of cause we can theme the content with PHP. But again we are exercising dript here. I will look forward to theme with dript.

Don't you think the dript code is neater than PHP? Happy hacking!

Lisp

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: