Author image
Senior Developer

Views 2: Making a drupal views block title link back to the view

We wrote an article about linking a view's block title to the companion page view, in Drupal 5. Someone asked for a Drupal 6 version, which can be quite easily done with a preprocess function, but it's not very flexible.

Instead we just need to create a new display plugin for Views 2, and that will allow us to be much more flexible in our approach.

This is my first display plugin, so it may be completely broken (though it works for me!) You'll just need to download and install the attached file like any other module.

Instead of adding a 'Block' display to your view, add the 'Block (title link)' display, and you'll get an extra option to define which display you'd like the block's title to link to. Simple.

[EDIT] It was completely broken! But it is now fixed and should be working nicely.

[EDIT] We lost the attachment in a server migration, but there is work to get this into views here: http://drupal.org/node/614944

Comments

One solution has always been to add a bit of footer or header text into the block, but it's a little tedious - and clients always find views hard to edit.

There's ongoing work to get this functionality into views proper:
http://drupal.org/node/614944

Your file cannot be unarchvied due to password prompt.

Really, there's no password set on the archive.

Alright, permission problem then.

tar -zxvf example-1.tar.gz
example/
example/example.info
tar: example/example.info: Cannot open: Permission denied
and so on

I think this must be a permission problem on your end, I can extract the files without issue on my linux box.

i just think that there should be an easier way to do this without modifying the code, i mean from the block admin interface, like when configuring a block in the block title field we should be able to add a link there. i hope the next Drupal releases would include this small update in them, i dont know if it's important to others as well but i think it's a very useful feature.

This looks very useful as often you want to link the title to it's page when it has both. How do you install this plugin?

Thanks

Install just like a module... I should've read that!
I'm getting an error:
Fatal error: Class 'views_plugin_display_block' not found in ...../sites/all/modules/example/views_plugin_display_block_link_title.inc on line 13

Hmmm...Looks like views isn't loading the parent class correctly. On what page are you seeing this error?

I created the view and saved it and it generated the error. The views UI seems okay but unable to edit without returning error.

I've fixed up the code in the example module so that it should now work.

thank you, the code works fine and is a good starting point for me making a custom module at the same time

Hi, thanks very much for this modul.

Is it somehow possible to show only the link to the view without any nodes underneath?

Hi,
Thanks for building this!
Would it with this plugin also possible to change the views title attribute from <h2> to <h1>.
I would like to have the views-title in the pagetitle and hopefully this will work.

Greetings,
Martijn

Nice article.The code works fine and is a good starting point for me making a custom module.Thanks for the module...
SEO

Drupal may be powerful, but it is also complex. The key is overcoming its long initial learning curve.Many casual users may prefer ease of use to powerful features, making Drupal less popular than more user-friendly CMSs.

Thanks,

Good post.I tried to setup a site using Drupal. However, I decided to switch to Joomla . I’ve heard many times that it’s easier to develop in Drupal. That would be a good thing because customizing the Joomla install is a really big pain.

I successfully installed the module. But whatever I tried, I just could not get the link I wanted.

Can you give a little tutorial?

Very informative question.Even I had this doubt...Thanks for your details.

Works perfectly for me, after I figured out that it really has to be installed - at first I thought copying the plugin into the views/plugin folder would be enough, but it really has to be installed like a module.

Cool plugin and great to learn more about what's possible with Views :) Thank you!

Any chance you could upload this to Drupal.org as a project?

If you're stuck for a module name, I suggest views_block_link_title :)

Something that requires a bit more configuration but allows more control for fancier things like image replacement:

In views_plugin_display_block_link_title.inc, set:
$info['views_block_link_path'] = url($this->view->get_url());
instead of:
$info['subject'] = l($info['subject'], $this->view->get_url(), array('html' => TRUE));

block.tpl has access to the whole $block object, so this can be retrieved and the link made in the template.

Thanks for taking the time to post such a detailed and informative article. It has given me a lot of inspiration.

Comments on this article are now closed, if you want to give us feeback you can use our contact form instead.