A working example

Well I finally have this thing working.
See example at
http://drupal5demo.cycletraffic.com/node/2
[correct at Jan 05 2008]

Having gotten the markup right with the microformat, the next step is to layer the javascript on top to produce the map.

At this stage, I could have gone to the drupal gmaps module for a start, but I preferred to work this out from scratch.

So how to you add javascript to a theme?
Well some of this is outlined on the Drupal API site at
http://api.drupal.org/api/function/drupal_add_js/5
but it wasn't very clear to me where to put that information to use. Benjamin Melançon was having a similar problem and that clarified that I couldn't use the function in a tpl file.
Of course, I could just directly link to the javascript in the page.tpl.php file [and indeed I ended up doing that for the Gmaps script], but I put this code
<?php
$path = drupal_get_path('theme', 'nokoala');
drupal_add_js($path.'/js/mapstraction.js',$type = 'theme');
drupal_add_js($path.'/js/events.js',$type = 'theme');
?>
in the template.php file, and that did the trick.

So what of the javascript itself?
Well I just used the code outlined at the inspirational article and made a few small adjustments to allow for the different markup, and different area being mapped.

So what happens next?
In some ways, I'm surpised I got this far at all!
But there are an infinite number of ways to improve this.
I'll start by imporving the markup, and I'll use the date information to create a hcalendar microformat

I'll work out the correct way to add the javascript code to the theme.
After that, I'll put the mapstraction code into a seperate module where it belongs.
I'll see whether the gmaps module is a better way to add the gmaps code.
I'll have a look at views...and what I might be able to do there...

Powered by Drupal, an open source content management system