Passing an argument to a Block View in Drupal 6

Q: How can I pass an argument to a ‘block view’ in Drupal 6?

A: There is no way to pass an argument to a block view in Drupal 6, but don’t panic as there is a way to achieve the same result through some slight-of-hand.

The use of arguments with Drupal views are vital for getting the most out of the views functionality. How are the arguments normal passed to a view?  Well, if a view is configured to produce a page then the arguments are easily passed as part of the requesting URL,  while if a view is embedded using code, then the arguments are passed in as part of the call to embed the view.  But if a view is configured to produce a block, how do you pass arguments to it?  The bad news is you can’t – the good news is that there is a way fake it and achieve the same result.

The trick involves providing a PHP handler within the view which will be called when the view is invoked without an expected argument (this is what happens when the block is displayed!).  We just arrange for this handler to retrieve and return the argument’s value and then the view will behave as required – just as if the argument had been passed to it in the first place.

To do this create the block view as normal and configure the required argument(s).  For each argument we choose the ‘Provide default argument’ option, and select the ‘PHP code’ sub-option.  We then provide some PHP code which will ‘get’ and return the argument’s value, it doesn’t really matter where or how the PHP code gets the argument once it returns the correct value.   Have a look at screen shot below:

Adding a default parameter

The example above is a bit simplistic as the PHP code just returns a static value – not very useful at all!  A more realistic or useful example  (inspired by one of the posts referenced below) would be to return the argument that was passed to the page that contains and displays the block.  Consider the mythical paths:


Here things are set-up so that ‘web-design’ and ‘illustration’ are arguments to the ‘projects’ page, they result in only the projects of that type being displayed.   Assuming we are using the pathauto module for nice clean URLs (as we almost always are!) then the following PHP code when provided as the default argument handler will get the URL, parse it and return the argument part to the view.

So there is is, it’s definitely not the easiest method in the world but at least it does provide a mechanism of getting those arguments to the view…


Drupal cron setup on unix plan

For setting up a Drupal maintenance cron job on the unix hosting plan, I have found that the following command works well:

/usr/bin/wget -O – -q -t 1

Original Source:

’25 Most Dangerous’ Programming Errors

The Register writes today about a new report which details the ’25 most dangerous’ programming errors – a list which was compiled by 30 organisations.  Very interesting indeed, nothing unexpected in the list really, but I reckon that a full review of it in the light of ongoing and recent project work could be very  worthwhile.

 It certainly calls into question the whole ‘if it builds, it works!’ paradigm of software development ;-)

Custom CCK Input Form in Drupal

We are using good old Drupal and its Content Construction Kit (CCK) once again to create a custom CMS for our client. One of the things that usually completely mystifies me time and time again is how to customise a new content type’s add/edit form layout.  So, lest I forget again in the future, here’s a link to a good article on the subject:

Native Lambda Expressions in C++? Yes Please!!

Today I came across a situation which brought it home to me again how (in my opinion) C++ could desperately do with native lambda function support.  The standard library has introduced a load of great algorithms, but providing predicates and the like to them is a real pain – and I think that because of this people tend to stick to hand rolling good old-fashioned loops.

Consider replacing a few different characters in a std::string with a single given character, e.g., replace the characters ‘$’ and ‘|’ with ‘_’.  A good way of doing this in C++ would be to use the boost regular expression library, but we could also use the std::replace_if() algorithm.  All we have to do to use this algorithm is to privide a predicate that indicates if a given character should be replaced or not (say called is_bad_char()), then we do something like:

 Looks easy enough, and it’s nice and concise.  All we have to do now is define is_bad_char(), something like:

I mean! what a pallava!  that’s quite a mouthful, would you really be bothered? You would have a loop coded in just the time it took to start to remember that syntax, never mind the typing. it also looks terribly inelegant.

Now when native lambda support arrvies we will be able to do something like this instead:

That’s much better… but not available yet, we will just have to wait for c++0x to arrive. In the mean time I will just have to use lambdas in the many other languages that support them and pine when using C++.

Debian steps into the Breach as Linksys NSLU2 NAS Dies

Our Linksys NSLU2 NAS finally died after a long and protracted fight to keep it on its legs and serving.  It has been acting up for a month or two now and now simply refuses to boot unless there are no drives plugged in (that’s not much use!!), I have a feeling that I could probably get it up and running again with freshly formatted disks etc., but I couldn’t really be bothered as I have wasted far too much time on the thing already.

It is only two years old, and although it is a very useable and low cost NAS solution I think that due to the shocking manner of its demise I couldn’t possibly recommend that anybody uses it at all!  My opinion has been backed up by the people to whom I have since talked, their Linksys NSLU2s suffered very similar fates at eirily similar ages.

Anyway, as the attached disks are formatted as linux ext3 volumes I just plugged them into a spare mini-ITX ‘black box’ type PC that we had here and installed a very slim and cut-down version of Debian with Samba.  A few quick fsck’s later confirmed that there was no damage to the volumes (phew!) and in an hour or two the disks were back on the network and stable.  A very acceptable gratis stop-gap solution thanks to Debian and a spare PC!

Thanks Winmerge!

I have recently been doing some fairly intensive merging and difference checking with Tortoise SVN and subversion and once again find myself thanking my luck stars that Winmerge is installed on my (windows) system just waiting to lend a helping hand!

For those who haven’t come across it Winmerge is an open source tool for visually checking file differences, it allows you to move individual changes or differences from one file to the other.  I have found it to be one of the best such tools and it’s free!  It also does a good job of comparing a whole directory tree of files.

Tortoise SVN can be configured to use Winmerge when showing differences etc. rather than its default difference visualiser, I find that this makes tortoise much more effective.  Instructions for configuring Winmerge as the default diff viewer can be found in the Tortoise help pages, but to summarise:

Right-Click on a folder in explorer, choose the ‘Tortoise SVN’ sub menu and then choose the ‘Settings’ menu option.  Click on the ‘Dif Viewer’ pane, select ‘External’  and  enter the following into the text-box below:

C:\Program Files\WinMerge\WinMergeU.exe -e -x -ub -dl %bname -dr %yname %base %mine

[the path entered will depend on where you installed Winmerge, for the real low-down on configuring this you had better check the documentation!]

Anyway, to sum up, if you find yourself struggling with comparing files or merging changes with subversion then I have found that Winmerge can be of great help, I can’t imagine doing without it anymore!

Captcha Gotcha

Here is an interesting article about the economics of human CAPTCHA ‘solving’ in India. $2 for a 1000 reads, that’s a lot of squinting at wavy, almost impossible to read letters to the dollar, can’t be good for the health! Apparently it’s part of their ‘data processing’ industry!

Technical Support Service for irish Web Designers Launched

We have finally got around to launching our new Technical Support Service for Irish Web Designers – a service designed to take care of the occasional programming and enginering aspects of a Web Designer’s Web development work, leaving them free to concentrate on the actual Web Design and Delivery.

This is a local service provided by experts in Ireland – so fast response times with the minimum of  administrative overhead are guaranteed.  This service is designed to be as useful for very small tasks (perhaps just an hour’s duration) as it is to larger tasks.

More details can be found here…

Displaying latest wordpress post on ‘random’ Web Page

Our client’s brief was to display their latest blog post on their main web page in a truncated form, their main web page is not part or their blog.  After a little searching I came across a wordpress plugin called Get-a-Post which seemed to promise just what we required.

It will retrieve a post, and sets the post’s data up correctly so that wordpress functions like the_title() and the_content() which must normally be called from within the wordpress loop can be called by php code that is outside of the wordpress loop, this is important to us as we want to display the data on a web page which is not part of the actual wordpress blog – from a ‘random’ page.

To install the plugin, just download it, and copy get-a-post.php to the blog’s wp-content/plugins/ directory.  Then goto the wordpress admin/plugins screen and activate it.

Once the plugin has been activated, its function get_a_post() can be called from any php script, if called with no parameters the latest post will be made active – perfect!  Before calling it make sure to include/require ‘wp-config.php’.  Here is an example script that gets the latest post’s title and content and packages it up into a div and some spans:

<?php require_once(“./wp-config.php”); ?>

<?php get_a_post(); ?>
<div class=”last_post_div”>
<span class=”last_post_title”><?php the_title()?></span> – <span class=”last_post_content”>
<?php echo get_the_content(); ?>