Monthly Archives: July 2011

This blog, flickr and youtube

This has turned into a very boring and impersonal blog about Drupal shortcuts! I should really do something about that. It’s really quite hard to work out what to write about – personal stuff doesn’t seem appropriate for something that future employers might read, but it’s difficult for me to write about things which interest me without them having personal elements. So I think, all in all, I’m going to stop worrying about that and just write about whatever I feel like. After all, I’ve got to harness my vitriol somehow (I have a rant about the quality of writing in 9 hours 9 persons 9 doors bottled up that I really ought to expunge for a start).

So, working in one of the most beautiful botanic gardens in the world (Kirstenbosch, Cape Town), I have been trying to take up photography again and set myself a challenge of taking 3 images that I am happy with per week. I’ve been a bit distracted because what I really want to do is explore the beautiful reddish-brown colour of the water in the mountain streams, and I’ve been looking at cheap underwater camera cases on Amazon. I did try taking a photo with my camera wrapped in a clear plastic bag (because I’m impatient and I’d have to order it from as there is no, but it wasn’t great and was kinda blurry:


I love the red colours and the quality of the sunshine in the water – the colours really are like that, I’ve not photoshopped it or enhanced it at all.

Anyway, the point is that I’m setting myself a goal – to upgrade this blog because goodness knows what version of wordpress it’s running on, to theme it so that it’s got my flickr feed ( and also my little kitty cat’s youtube channel 🙂, because, honestly, I’m not just some kind of Drupal/programming nerd!

Drupal 6, theming views: preprocess functions

I couldn’t find this documented anywhere – the most useful thing on is this thread – and in fact only worked it out by just trying random things until they worked, so (as with all of the other Drupal posts) I am documenting it here for posterity.

If you want to do something like show a certain value in a certain field in your list-formatted view depending on what is in another field in the same row, (so for example, a download link or an ’email author for copy of document’ link, depending on the third cck field (do you prefer people to download this document or email the author), then you might want to do this using theme level preprocess functions. Preprocess functions allow you to manipulate data more easily than you would be able to in the template file itself. Well, it certainly looks neater anyway.

I’m using the zen theme, so keep in mind that the way this works might have something to do with that. You first have to create a .tpl.php named corresponding to the function you want to override:

  1. Go to /admin/build/views/edit/[yourviewname]
  2. Click on whichever view display you wish and under basic settings click on ‘Theme information’. This gives you a hierarchy of template name overrides for your views.
  3. Make a note of the last template name suggestion in either the style output or the row style output. So if you decided to override the row style output and your view is called ‘documents’, and your display is ‘page 1’, the template name you choose will be views-view-fields–documents–page-1.tpl.php
  4. Go to the views module folder and in the theme subfolder copy the template with the first name in the hierarchy that you chose in the previous point. In the previous example it would be views-view-fields.tpl.php. This needs to go into your theme’s directory, and if you’re using zen it seems to go into [yourthemename]/templates

Remember to clear your theme cache once you have done this! This is very useful anyway, as you can now change the tpl.php however you want to. But if you want to preprocess the data before it enters the template, you need to create a function in your theme’s template.php named like this: [yourthemename]_preprocess_[the name of the views template you copied with – changed to _].tpl.php. So in the previous example, it would be function mytheme_preprocess_views_view_fields__documents__page_1(&$vars) {}.

I don’t know how these preprocess functions work, it might very well have something to do with zen registering some views preprocess functions for you, but it does work and it’s very useful and finding info about it on the internet was a bit of a mission for me.

The search box in the Zen Drupal Theme

Firstly you have to enable to search module – admin > site building > modules
Then you have to enable the search in the theme – admin > site building > themes > configure > yourzensubtheme (under toggle display)
Then you can configure the search settings – admin > site configuration > search settings
You need to set permissions for the search module too – admin > user management > permissions.

Drupal XML sitemap only 1 link

I had to apply a patch in order to get xmlsitemap working at all in my windows environment, I got an error:

Fatal error: Uncaught exception 'XMLSitemapGenerationException' with message 'Could not open file sites/default/files/xmlsitemap/NXhscRe0440PFpI5dSznEVgmauL25KojD7u4e9aZwOM/1.xml for writing.'

I found the patch to fix that here

Once that’s done, keep in mind that you have to install the XML sitemap node module as well as the xmlsitemap base module for the site map to actually generate more than 1 link. After you’ve got xml sitemap node installed, you can include individual content types in the content type settings page – /admin/content/node-type/page.