Pezholio

26 Jun, 2009

Widgetising Local Government Content

Posted by: Pez In: Council Stuff|Web Development

John Smith's - because it's got a widget (Not that I'd actually drink the stuff)

With the recent publication of the Digital Britain report and Gordon Brown calling on Tim Berners-Lee to help open up access to government data, there’s been a lot of talk about public organisations opening up data.

Most of this has focused around APIs and linked data (something I’m very passionate about already), but there’s much simpler ways to get data out there that might be useful to those people who might have a website, know their way a bit round HTML, but aren’t willing to get their hands dirty with XML, JSON or RDF.

I’m talking of course, about widgets, these are little bits of (often Javascript) code that people can copy and paste into their own websites. These can then be used by local blogs, newspapers or other websites to publish your content in a quick and easy way.

I’ve had a go at doing a few widgets, publishing food safety inspections and planning applications as widgets and I’m looking to do more in the future. Fellow blogger and techy Philip John has even turned one of our widgets into a WordPress-compatible widget, which I’m proudly sporting on the right here.

Essentially, what you’re doing is pulling information from a database (using PHP or whatever server-side technology you fancy) and outputting it as javascript code, wrapping it all in a document.write function. You can also use inline styling to style your widget, making sure you override any potential styles that might be overridden by the user’s stylesheet. A quick and dirty example is below:


<?php
$query = "SELECT * FROM database";
$result = mysql_query($query) or die(mysql_error());
echo "document.write('";
echo "<h2 style=\"font-size: 18px; font-weight: bold;\">Planning Applications for Foo on Bar Council</h2>";
while ($row = mysql_fetch_array($result)) {
echo "<p><a href=\"".$row['link']."\">".$row['address']."</a>";
echo "<p>".$row['proposal']."</p>";
}
echo "');";
?>

Note: It’s very important that you make sure you get rid of all line breaks when you actually publish your content, otherwise you’ll get a Javascript error and the content won’t show up.

Once you’ve done this, you can then upload the script and then call it in a script tag, like below:

<script type="text/javascript" src="http://www.mysite.com/myscript.php"></script>

And here’s one I made earlier!:

Really, the only limit is your imagination, so get out there and widgetise! It’s not a replacement for APIs, but it’s a good alternative for folks who might not be comfortable with the big stuff.

(P.S. The John Smith’s is there because it’s got a widget in the can, I’m not advocating the drinking of John Smith’s – it’s horrible stuff. Give me a proper cask ale any day)

10 Responses to "Widgetising Local Government Content"

1 | paul canning

June 26th, 2009 at 9:12 am

Avatar

Very good!

The use by others of widgets is the key point – they’re a marketing tool for services and information. So when they’re built they then need to be promoted, and to the particular audience for them.

I did one a few years back which was local sports events for kids and young people and tried to get it on school websites. What I found was it was a bit early – most school websites weren’t very good – and not ‘official’ enough – my bosses didn’t really want it or (try to) understand the concept.

So you do need to do them as part of a strategy for increasing audience for specific services on the wider web rather than just directing people to the council website, and that’s a pretty new concept for government.

It’s not though for the rest of the web, which is why more interactive ads exist ‘check hotels’, ‘get insurance quote’ etc.

It’s always struck me as an ideal way to find audiences for council services.

2 | Pez

June 26th, 2009 at 9:33 am

Avatar

Good call Paul, something like kids’ activities is an ideal thing too. There’s a lot of schools out there, and, even now school webmasters tend to be enthusiastic amateurs (often teachers) who are pressed for time. A quick email round to schools asking them to add a line of code is a quick win. I’ll certainly bare this in mind for the future!

Another thing I thought about was an iGoogle (or similar) widget telling people when their next bin collection is or even their council tax balance. There’s loads more uses for this kind of tech, it all depends on what data you’ve got, and, like I say, your imagination!

3 | Tim Hobbs

June 26th, 2009 at 9:55 am

Avatar

Excellent post. You’ve got me thinking about bins again (although I think of little else)…

A little Javascript snippet that allows a council (or anyone else) to publish tomorrow’s bin rounds and what they are collecting. Nice idea.

4 | paul canning

June 26th, 2009 at 10:01 am

Avatar

Staying with the schools example, it’s a bit more complex to get them used I think. For example you need to get them in the right places on school websites and signposted. You need to be prepared to give advice or even some straightforward usage requirements. It’s probably a good idea to do something like produce a leaflet telling people it’s there as well.

Another thing is to look at audience. Schools would be kids and teachers, where do parents look? Locally here there’s an amateur site which pulls info on events/outings for families together which comes tops in local google results. Also national commercial sites which have localised pages tend to score high for searches.

Simple things like stopping families in the high street and asking would pull up other places which mightn’t be obvious. I suspect word of mouth would be significant so maybe also look to email?

Another point is to make sure they’re tagged correctly so you get good stats out of them.

5 | paul canning

June 26th, 2009 at 10:02 am

Avatar

p.s. your paragraph spacing is borked! :]

6 | Pez

June 26th, 2009 at 10:08 am

Avatar

Yeah, I noticed that. Was hoping noone else would! ;)

Fixed now though!

7 | Kasper Sorensen

June 30th, 2009 at 11:40 am

Avatar

As someone who’s only recently started getting my hands dirty with data mashing and the use of public data, this was really helpful.

I’m only half decent at PHP and WordPress hacking and the main barrier is the technical side, getting the data from the source and displaying the final output. Lately I have been using Yahoo Pipes which seems very powerful as well. It does output as JSON which I understand can be displayed using JavaScript, but that is something I still need to get to grips with.

8 | Pez

June 30th, 2009 at 11:45 am

Avatar

Glad to be of service! JSON takes a bit of getting your head round, but you might want to check out the $.getJSON() method in jQuery ( http://docs.jquery.com/Ajax/jQuery.getJSON ).

I’m by no means a Javascript expert, and I find libraries like jQuery and Prototype make things a lot easier!

9 | stevieflow

July 19th, 2009 at 3:37 pm

Avatar

Pez, Paul

Sorry to have arrived a little late to this thread, but the widget of activities for young people is something we are working towards with the Plings project. We have just aggregated a load of data from 20 local authorities around summer holiday activities, so the next step is to push it further out there.

As soon as we have it together Ill post a note on here!

Thanks

Steven

10 | Pez

July 26th, 2009 at 7:56 pm

Avatar

Good stuff, let us know how you get on! :)

Comment Form

Where I’m at