You are here

Managing layouts in Drupal

Posted at 16:29 on Sun, 2nd September 2012 in drupal.

Comparing the different options and modules available for managing Layouts in Drupal.

A few weeks ago, I had the privilege of presenting at the local monthly DrupalWA meetup. The topic was managing layouts in Drupal. There was a lot to cover in a short space of time, so I thought I'd elaborate further on a few things in writing. So here goes:

The blocks module found in Drupal core, can be used for managing blocks on your web pages. It works very well for brochure sites, but for larger sites it becomes very cumbersome because of its limitations. e.g. you can't actually tell which blocks (or regions) are visible in which parts of your site without individually editing each block. The good news is there are contributed modules which can solve this problem as well as do a whole lot more.

Before I talk about these contributed modules, I should say that these can optionally be used in tandem with your normal blocks management interface or alternatively can completely replace the blocks management interface (but we won't go into that here). They do this either through additional add-on modules or by specific settings. My personal preference has been to use blocks for basic things in your header and footer (i.e. menus or copyright blocks) but then leave the body of the page to one of these modules.

Context Module

The Context module allows you to create contexts, which are basically, a set of conditions with a set of reactions e.g. when content is of type x display these blocks in these regions. That's pretty much the basics of Context. The context configurations themselves are exportable into features, and there are lots of other modules and themes that build on the context module, such as Omega.

If you're looking to learn Context check out this very good video from mustard seed.

Panels Module

The Panels module is one of the more powerful methods for managing layouts in Drupal, but at the same time has a fairly steep learning curve. If you're new to Panels, you want to give yourself sufficient time to experiment with the module before you start using it on your next big web project.

When you download the module, you'll also need to install CTools, and to get things going you want to enable the 'Page Manager' module that comes with CTools too - if you don't, Panels isn't really very useful from what i could tell - without 'Page Manager' basically you can only create panel HTTP response code variants (which I've not found a use for yet).

Panels is path driven - by that I mean, a different panel exists depending on the path, i.e. you may have a panel for node view pages, a panel for user profile pages, and so on. Within each panel, you have variants, which allow you to have different layouts depending on the selection rules (conditions). e.g. you may have a panel for nodes, but within the panel you may have a variant for one node type, and another variant for another node type. Each variant lets you configure different layouts, and therefore different fields or blocks for display.

Panels has a lot of other advanced features too, like Contexts (n.b. this is not to be confused with the Context Module) which lets you bring other things (like a node) into the scope of the Panel. An example of a context might be that you have a panel for your product listing pages (taxonomy term pages) and you want to bring into context a specific node that contains your shipping conditions - as you might want to display this on all product pages.

Panels also has a very rich plugin system for providing custom layouts, access controls, content blocks (called content types in panels - not to be confused with drupal content types), and styles. These plugins are written as ctools API plugins and basically allow for maximum flexibility. I've linked to a few tutorials there, but when you download ctools (dependency for Panels) it comes with a lot of pre-written plugins, which are perfect to use an examples (just look in ctools/plugins/).

If you are serious about learning panels, check out some of the videos on this handbook page.

Display Suite (DS)

The Display Suite module is in some ways 'the new kid on the block', as it has only been around (a stable version anyway) since Drupal 7. Don't let that put you off though, DS is very flexible, and powerful, and unlike the Panels module doesn't have its own terminology or its own unique configuration interface to learn.

DS essentially makes the 'Manage Display' tabs on your content types (and other areas) a lot more powerful by letting you select layouts (which may have their own regions) for different view modes (i.e. teaser, full content, etc). On top of this it gives you more options to manage tags, and formats of the field content, and also lets you add custom display fields to the manage display tab too. The custom display fields basically let you do anything like pull in a block as a field, or process and then display a field a bit differently.

DS can also integrate with Views. Basically it lets you manage the fields of your view in a DS view mode, as opposed to Views, which may or may not be a good thing (possibly needs another post to discuss).

If you're experienced with Panels, you can also use the Panels interactive layout manager as the interface for the 'Manage Display' tab of DS too.

To learn display suite checkout these screencasts: - they were really helpful to me, and start from the very basics and go up to the advanced features too.

To the future

Ideally it would be better if there weren't so many different options for managing layouts in Drupal, and you didn't require contributed modules for what is a fairly important part of a website - managing the layout. The good news is, this is in the plan for Drupal 8 (due out end of 2013). It's currently being discussed under the guise of the 'Concept Model' over on g.d.o. The following video talks a bit about how layouts may eventually work in Drupal 8 too.

More Comparisons

For more information about the comparison of some of these modules, check out the following posts:

In Summary

If you've not used any of the layout modules before but need something more manageable than the Drupal core Blocks module, then use Context. If you've used Context and need more flexibility, use Display Suite, and if you're already using Panels and love it, well keep loving it, but give the Display Suite Module a go too one day.