Drupal: Lightbox overlay with Views 3 and Magnific Popup

This tutorial will take you through the steps of having your Drupal 7 content open up inside a lightbox overlay when it is selected from a view. We'll also throw in a permalink for convenience and SEO.

You should already have a basic working knowledge of Drupal theming and Views 3. 

Drupal: Attach a site-wide contact form to a page or block

As far as website contact forms go, Drupal's core Contact module provides pretty much everything it should right out of the box. But what if you want to add more information to the page (mailing address, for example), or position the form as a block, say, in a sidebar? In the first case, you would have the form automatically load inside another page node (such as we've done with our own Contact us page). In the second, you could create an empty block and attach the contact form to it. Here's how:

Drupal tip: Programmatically output a block

The following PHP code will print out a block in Drupal 7:

$module = 'system';
$delta = 'main';

//Load the block object.
$block = block_load($module, $delta);

// Get a renderable array.
$render_array = _block_get_renderable_array(_block_render_blocks(array($block)));

// Render the block element.
$output = render($render_array);

print $output;

To locate $module and $delta, go to admin/structure/block and click on the "configure" link next to the block you want to print. The strings will be shown in the URL as such: admin/structure/block/manage/[module]/[delta]/configure.

Drupal: Override output of taxonomy term page per vocabulary

Occasionally it is necessary to alter the output that is generated when a user clicks on a taxonomy term link. Generating custom mark-up for all taxonomy term pages is a simple two step process:

  1. Copy page.tpl.php into your theme folder and rename it page--taxonomy.tpl.php. 

  2. Clear all caches.

But what if you want unique mark-up for terms belonging to a particular vocabulary? Still pretty simple, but it does involve a couple more steps:

Drupal: Turn your main menu into a Superfish menu (and learn some basics along the way)

There are a few of us control freaks DIY types who prefer to tinker with things at the source, even if it takes a little more time and effort. But since most people will likely opt to install the excellent Superfish Drupal module, which will essentially have you set up in a couple of clicks, this post is more of an excuse to illustrate a few theming basics; for instance:

  • how to use a theme function to override Drupal's default HTML output,
  • how to alter rendered output using a preprocessor function,
  • how to load javascript and css files into your theme.

We'll use the plugin's "Basic" menu in this example. The fine tuning is up to you. 

Subscribe to Othermachines Blog